2010-10-03 23:04:50 +02:00
|
|
|
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "base/compiler_specific.h"
|
|
|
|
|
2011-01-12 00:46:14 +01:00
|
|
|
#include "third_party/WebKit/Source/WebCore/config.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
MSVC_PUSH_WARNING_LEVEL(0);
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "ApplicationCacheStorage.h"
|
|
|
|
#include "CrossOriginPreflightResultCache.h"
|
2011-02-09 23:04:35 +01:00
|
|
|
#include "DocumentLoader.h"
|
2010-11-16 17:01:14 +01:00
|
|
|
#include "MemoryCache.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "TextEncoding.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/src/WebFrameImpl.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
MSVC_POP_WARNING();
|
2011-01-06 20:26:45 +01:00
|
|
|
#undef LOG
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
#include "browser_webkit_glue.h"
|
2010-11-18 22:05:25 +01:00
|
|
|
#include "cef_context.h"
|
|
|
|
|
2011-09-30 11:22:54 +02:00
|
|
|
#include "base/file_util.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "base/logging.h"
|
2011-09-23 02:16:03 +02:00
|
|
|
#include "base/memory/scoped_ptr.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "base/path_service.h"
|
2011-09-10 21:40:03 +02:00
|
|
|
#include "base/string_util.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "base/string16.h"
|
|
|
|
#include "net/base/mime_util.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
|
2011-12-16 15:51:10 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
|
2011-09-30 11:22:54 +02:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
2011-07-03 02:03:30 +02:00
|
|
|
#include "webkit/glue/user_agent.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "webkit/glue/webkit_glue.h"
|
2011-09-10 21:40:03 +02:00
|
|
|
#include "webkit/plugins/npapi/plugin_list.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
// Generated by GRIT
|
|
|
|
#include "grit/webkit_resources.h"
|
|
|
|
|
|
|
|
using WebKit::WebFrameImpl;
|
|
|
|
|
|
|
|
namespace webkit_glue {
|
|
|
|
|
2011-10-31 16:40:54 +01:00
|
|
|
void InitializeResourceBundle(const std::string& locale) {
|
2011-09-30 11:22:54 +02:00
|
|
|
// Load chrome.pak (on Mac) and the appropiate locale pack.
|
|
|
|
const std::string loaded_locale =
|
|
|
|
ResourceBundle::InitSharedInstance(locale);
|
|
|
|
CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale;
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
2011-10-12 12:54:21 +02:00
|
|
|
// Explicitly load chrome.pak on Windows. Use the module (libcef.dll)
|
|
|
|
// directory to match the location of the locale folder.
|
2011-09-30 11:22:54 +02:00
|
|
|
FilePath chrome_pack_path;
|
2011-10-12 12:54:21 +02:00
|
|
|
PathService::Get(base::DIR_MODULE, &chrome_pack_path);
|
2011-09-30 11:22:54 +02:00
|
|
|
chrome_pack_path = chrome_pack_path.AppendASCII("chrome.pak");
|
|
|
|
if (file_util::PathExists(chrome_pack_path))
|
|
|
|
ResourceBundle::AddDataPackToSharedInstance(chrome_pack_path);
|
|
|
|
else
|
|
|
|
NOTREACHED() << "Could not load chrome.pak";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-10-31 16:40:54 +01:00
|
|
|
void CleanupResourceBundle() {
|
|
|
|
ResourceBundle::CleanupSharedInstance();
|
|
|
|
}
|
|
|
|
|
2011-09-30 11:22:54 +02:00
|
|
|
string16 GetLocalizedString(int message_id) {
|
|
|
|
return ResourceBundle::GetSharedInstance().GetLocalizedString(message_id);
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
bool IsMediaPlayerAvailable() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitializeTextEncoding() {
|
|
|
|
WebCore::UTF8Encoding();
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Handle<v8::Context> GetV8Context(WebKit::WebFrame* frame)
|
|
|
|
{
|
|
|
|
WebFrameImpl* webFrameImpl = static_cast<WebFrameImpl*>(frame);
|
|
|
|
WebCore::Frame* core_frame = webFrameImpl->frame();
|
|
|
|
return WebCore::V8Proxy::context(core_frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearCache()
|
|
|
|
{
|
2011-02-15 19:07:24 +01:00
|
|
|
if (WebCore::memoryCache()->disabled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Clear the memory cache by disabling and then re-enabling it.
|
|
|
|
WebCore::memoryCache()->setDisabled(true);
|
|
|
|
WebCore::memoryCache()->setDisabled(false);
|
|
|
|
|
|
|
|
// Empty the Cross-Origin Preflight cache
|
|
|
|
WebCore::CrossOriginPreflightResultCache::shared().empty();
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(OS_LINUX)
|
|
|
|
int MatchFontWithFallback(const std::string& face, bool bold,
|
|
|
|
bool italic, int charset) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetFontTable(int fd, uint32_t table, uint8_t* output,
|
|
|
|
size_t* output_length) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-06 20:26:45 +01:00
|
|
|
// Adapted from Chromium's BufferedResourceHandler::ShouldDownload
|
|
|
|
bool ShouldDownload(const std::string& content_disposition,
|
|
|
|
const std::string& mime_type)
|
|
|
|
{
|
|
|
|
std::string type = StringToLowerASCII(mime_type);
|
|
|
|
std::string disposition = StringToLowerASCII(content_disposition);
|
|
|
|
|
|
|
|
// First, examine content-disposition.
|
|
|
|
if (!disposition.empty()) {
|
|
|
|
bool should_download = true;
|
|
|
|
|
|
|
|
// Some broken sites just send ...
|
|
|
|
// Content-Disposition: ; filename="file"
|
|
|
|
// ... screen those out here.
|
|
|
|
if (disposition[0] == ';')
|
|
|
|
should_download = false;
|
|
|
|
|
|
|
|
if (disposition.compare(0, 6, "inline") == 0)
|
|
|
|
should_download = false;
|
|
|
|
|
|
|
|
// Some broken sites just send ...
|
|
|
|
// Content-Disposition: filename="file"
|
|
|
|
// ... without a disposition token... Screen those out.
|
|
|
|
if (disposition.compare(0, 8, "filename") == 0)
|
|
|
|
should_download = false;
|
|
|
|
|
|
|
|
// Also in use is Content-Disposition: name="file"
|
|
|
|
if (disposition.compare(0, 4, "name") == 0)
|
|
|
|
should_download = false;
|
|
|
|
|
|
|
|
// We have a content-disposition of "attachment" or unknown.
|
|
|
|
// RFC 2183, section 2.8 says that an unknown disposition
|
|
|
|
// value should be treated as "attachment".
|
|
|
|
if (should_download)
|
|
|
|
return true;
|
2010-10-16 21:10:11 +02:00
|
|
|
}
|
2011-01-06 20:26:45 +01:00
|
|
|
|
|
|
|
// Mirrors WebViewImpl::CanShowMIMEType()
|
|
|
|
if (type.empty() || net::IsSupportedMimeType(type))
|
|
|
|
return false;
|
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
// Finally, check the plugin list.
|
2011-09-11 00:05:55 +02:00
|
|
|
bool allow_wildcard = false;
|
2011-09-10 21:40:03 +02:00
|
|
|
std::vector<webkit::WebPluginInfo> plugins;
|
|
|
|
webkit::npapi::PluginList::Singleton()->GetPluginInfoArray(
|
|
|
|
GURL(), type, allow_wildcard, NULL, &plugins, NULL);
|
|
|
|
|
|
|
|
// If any associated plugins exist and are enabled don't allow the download.
|
|
|
|
if (!plugins.empty()) {
|
|
|
|
std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin();
|
|
|
|
for (; it != plugins.end(); ++it) {
|
2011-09-23 02:16:03 +02:00
|
|
|
if (webkit_glue::IsPluginEnabled(*it))
|
2011-09-10 21:40:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2010-10-16 21:10:11 +02:00
|
|
|
}
|
|
|
|
|
2011-09-23 02:16:03 +02:00
|
|
|
bool IsPluginEnabled(const webkit::WebPluginInfo& plugin) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
} // namespace webkit_glue
|