#include "android_webview/browser/aw_browser_context.h"
#include "android_webview/browser/aw_browser_main_parts.h"
+#include "android_webview/browser/aw_browser_permission_request_delegate.h"
#include "android_webview/browser/aw_contents_client_bridge_base.h"
#include "android_webview/browser/aw_contents_io_thread_client.h"
#include "android_webview/browser/aw_cookie_access_policy.h"
+#include "android_webview/browser/aw_dev_tools_manager_delegate.h"
#include "android_webview/browser/aw_quota_permission_context.h"
#include "android_webview/browser/aw_web_preferences_populater.h"
#include "android_webview/browser/jni_dependency_factory.h"
+#include "android_webview/browser/net/aw_url_request_context_getter.h"
#include "android_webview/browser/net_disk_cache_remover.h"
#include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.h"
#include "android_webview/common/render_view_messages.h"
#include "android_webview/common/url_constants.h"
+#include "base/android/locale_utils.h"
#include "base/base_paths_android.h"
#include "base/path_service.h"
+#include "components/cdm/browser/cdm_message_filter_android.h"
#include "content/public/browser/access_token_store.h"
#include "content/public/browser/browser_message_filter.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_security_policy.h"
+#include "content/public/browser/permission_type.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
-#include "grit/ui_resources.h"
+#include "content/public/common/web_preferences.h"
#include "net/android/network_library.h"
#include "net/ssl/ssl_cert_request_info.h"
#include "net/ssl/ssl_info.h"
-#include "ui/base/l10n/l10n_util_android.h"
#include "ui/base/resource/resource_bundle.h"
-#include "webkit/common/webpreferences.h"
+#include "ui/resources/grit/ui_resources.h"
using content::BrowserThread;
+using content::ResourceType;
namespace android_webview {
namespace {
// BrowserMessageFilter methods.
virtual void OverrideThreadForMessage(
const IPC::Message& message,
- BrowserThread::ID* thread) OVERRIDE;
+ BrowserThread::ID* thread) override;
virtual bool OnMessageReceived(
- const IPC::Message& message,
- bool* message_was_ok) OVERRIDE;
+ const IPC::Message& message) override;
void OnShouldOverrideUrlLoading(int routing_id,
const base::string16& url,
};
AwContentsMessageFilter::AwContentsMessageFilter(int process_id)
- : process_id_(process_id) {
+ : BrowserMessageFilter(AndroidWebViewMsgStart),
+ process_id_(process_id) {
}
AwContentsMessageFilter::~AwContentsMessageFilter() {
}
}
-bool AwContentsMessageFilter::OnMessageReceived(const IPC::Message& message,
- bool* message_was_ok) {
+bool AwContentsMessageFilter::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
- IPC_BEGIN_MESSAGE_MAP_EX(AwContentsMessageFilter, message, *message_was_ok)
- IPC_MESSAGE_HANDLER(AwViewHostMsg_ShouldOverrideUrlLoading,
- OnShouldOverrideUrlLoading)
- IPC_MESSAGE_HANDLER(AwViewHostMsg_SubFrameCreated, OnSubFrameCreated)
- IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_BEGIN_MESSAGE_MAP(AwContentsMessageFilter, message)
+ IPC_MESSAGE_HANDLER(AwViewHostMsg_ShouldOverrideUrlLoading,
+ OnShouldOverrideUrlLoading)
+ IPC_MESSAGE_HANDLER(AwViewHostMsg_SubFrameCreated, OnSubFrameCreated)
+ IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
// content::AccessTokenStore implementation
virtual void LoadAccessTokens(
- const LoadAccessTokensCallbackType& request) OVERRIDE {
+ const LoadAccessTokensCallbackType& request) override {
AccessTokenStore::AccessTokenSet access_token_set;
// AccessTokenSet and net::URLRequestContextGetter not used on Android,
// but Run needs to be called to finish the geolocation setup.
request.Run(access_token_set, NULL);
}
virtual void SaveAccessToken(const GURL& server_url,
- const base::string16& access_token) OVERRIDE { }
+ const base::string16& access_token) override { }
private:
virtual ~AwAccessTokenStore() { }
DISALLOW_COPY_AND_ASSIGN(AwAccessTokenStore);
};
-}
+} // namespace
std::string AwContentBrowserClient::GetAcceptLangsImpl() {
// Start with the currnet locale.
- std::string langs = l10n_util::GetDefaultLocale();
+ std::string langs = base::android::GetDefaultLocale();
// If we're not en-US, add in en-US which will be
// used with a lower q-value.
- if (StringToLowerASCII(langs) != "en-us") {
+ if (base::StringToLowerASCII(langs) != "en-us") {
langs += ",en-US";
}
return langs;
AwContentBrowserClient::~AwContentBrowserClient() {
}
-void AwContentBrowserClient::AddCertificate(net::URLRequest* request,
- net::CertificateMimeType cert_type,
+void AwContentBrowserClient::AddCertificate(net::CertificateMimeType cert_type,
const void* cert_data,
size_t cert_size,
int render_process_id,
- int render_view_id) {
+ int render_frame_id) {
if (cert_size > 0)
net::android::StoreCertificate(cert_type, cert_data, cert_size);
}
content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
host->GetID(), android_webview::kContentScheme);
content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
- host->GetID(), content::kFileScheme);
+ host->GetID(), url::kFileScheme);
host->AddFilter(new AwContentsMessageFilter(host->GetID()));
+ host->AddFilter(new cdm::CdmMessageFilterAndroid());
}
-net::URLRequestContextGetter*
-AwContentBrowserClient::CreateRequestContext(
+net::URLRequestContextGetter* AwContentBrowserClient::CreateRequestContext(
content::BrowserContext* browser_context,
- content::ProtocolHandlerMap* protocol_handlers) {
- DCHECK(browser_context_.get() == browser_context);
- return browser_context_->CreateRequestContext(protocol_handlers);
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors) {
+ DCHECK_EQ(browser_context_.get(), browser_context);
+ return browser_context_->CreateRequestContext(protocol_handlers,
+ request_interceptors.Pass());
}
net::URLRequestContextGetter*
content::BrowserContext* browser_context,
const base::FilePath& partition_path,
bool in_memory,
- content::ProtocolHandlerMap* protocol_handlers) {
- DCHECK(browser_context_.get() == browser_context);
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors) {
+ DCHECK_EQ(browser_context_.get(), browser_context);
+ // TODO(mkosiba,kinuko): request_interceptors should be hooked up in the
+ // downstream. (crbug.com/350286)
return browser_context_->CreateRequestContextForStoragePartition(
- partition_path, in_memory, protocol_handlers);
+ partition_path, in_memory, protocol_handlers,
+ request_interceptors.Pass());
}
std::string AwContentBrowserClient::GetCanonicalEncodingNameByAliasName(
}
void AwContentBrowserClient::AppendExtraCommandLineSwitches(
- CommandLine* command_line,
+ base::CommandLine* command_line,
int child_process_id) {
NOTREACHED() << "Android WebView does not support multi-process yet";
}
std::string AwContentBrowserClient::GetApplicationLocale() {
- return l10n_util::GetDefaultLocale();
+ return base::android::GetDefaultLocale();
}
std::string AwContentBrowserClient::GetAcceptLangs(
return GetAcceptLangsImpl();
}
-gfx::ImageSkia* AwContentBrowserClient::GetDefaultFavicon() {
+const gfx::ImageSkia* AwContentBrowserClient::GetDefaultFavicon() {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
// TODO(boliu): Bundle our own default favicon?
return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
return false;
}
-bool AwContentBrowserClient::AllowWorkerFileSystem(
+void AwContentBrowserClient::AllowWorkerFileSystem(
const GURL& url,
content::ResourceContext* context,
- const std::vector<std::pair<int, int> >& render_frames) {
+ const std::vector<std::pair<int, int> >& render_frames,
+ base::Callback<void(bool)> callback) {
// Android WebView does not yet support web workers.
- return false;
+ callback.Run(false);
}
bool AwContentBrowserClient::AllowWorkerIndexedDB(
int cert_error,
const net::SSLInfo& ssl_info,
const GURL& request_url,
- ResourceType::Type resource_type,
+ ResourceType resource_type,
bool overridable,
bool strict_enforcement,
+ bool expired_previous_decision,
const base::Callback<void(bool)>& callback,
content::CertificateRequestResultType* result) {
AwContentsClientBridgeBase* client =
void AwContentBrowserClient::SelectClientCertificate(
int render_process_id,
int render_frame_id,
- const net::HttpNetworkSession* network_session,
net::SSLCertRequestInfo* cert_request_info,
const base::Callback<void(net::X509Certificate*)>& callback) {
- LOG(WARNING) << "Client certificate request from "
- << cert_request_info->host_and_port.ToString()
- << " rejected. (Client certificates not supported in WebView)";
- callback.Run(NULL);
+ AwContentsClientBridgeBase* client =
+ AwContentsClientBridgeBase::FromID(render_process_id, render_frame_id);
+ if (client) {
+ client->SelectClientCertificate(cert_request_info, callback);
+ } else {
+ callback.Run(NULL);
+ }
}
-blink::WebNotificationPresenter::Permission
+blink::WebNotificationPermission
AwContentBrowserClient::CheckDesktopNotificationPermission(
const GURL& source_url,
content::ResourceContext* context,
int render_process_id) {
// Android WebView does not support notifications, so return Denied here.
- return blink::WebNotificationPresenter::PermissionDenied;
+ return blink::WebNotificationPermissionDenied;
}
void AwContentBrowserClient::ShowDesktopNotification(
const content::ShowDesktopNotificationHostMsgParams& params,
+ content::BrowserContext* browser_context,
int render_process_id,
- int render_view_id,
- bool worker) {
+ scoped_ptr<content::DesktopNotificationDelegate> delegate,
+ base::Closure* cancel_callback) {
NOTREACHED() << "Android WebView does not support desktop notifications.";
}
-void AwContentBrowserClient::CancelDesktopNotification(
- int render_process_id,
- int render_view_id,
- int notification_id) {
- NOTREACHED() << "Android WebView does not support desktop notifications.";
+void AwContentBrowserClient::RequestPermission(
+ content::PermissionType permission,
+ content::WebContents* web_contents,
+ int bridge_id,
+ const GURL& requesting_frame,
+ bool user_gesture,
+ const base::Callback<void(bool)>& result_callback) {
+ int render_process_id = web_contents->GetRenderProcessHost()->GetID();
+ int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
+ GURL origin = requesting_frame.GetOrigin();
+ AwBrowserPermissionRequestDelegate* delegate =
+ AwBrowserPermissionRequestDelegate::FromID(render_process_id,
+ render_view_id);
+ switch (permission) {
+ case content::PERMISSION_GEOLOCATION:
+ if (!delegate) {
+ DVLOG(0) << "Dropping GeolocationPermission request";
+ result_callback.Run(false);
+ return;
+ }
+ delegate->RequestGeolocationPermission(origin, result_callback);
+ break;
+ case content::PERMISSION_PROTECTED_MEDIA:
+ if (!delegate) {
+ DVLOG(0) << "Dropping ProtectedMediaIdentifierPermission request";
+ result_callback.Run(false);
+ return;
+ }
+ delegate->RequestProtectedMediaIdentifierPermission(origin,
+ result_callback);
+ break;
+ case content::PERMISSION_MIDI_SYSEX:
+ case content::PERMISSION_NOTIFICATIONS:
+ case content::PERMISSION_PUSH_MESSAGING:
+ NOTIMPLEMENTED() << "RequestPermission not implemented for "
+ << permission;
+ break;
+ case content::PERMISSION_NUM:
+ NOTREACHED() << "Invalid RequestPermission for " << permission;
+ break;
+ }
+}
+
+void AwContentBrowserClient::CancelPermissionRequest(
+ content::PermissionType permission,
+ content::WebContents* web_contents,
+ int bridge_id,
+ const GURL& origin) {
+ int render_process_id = web_contents->GetRenderProcessHost()->GetID();
+ int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
+ AwBrowserPermissionRequestDelegate* delegate =
+ AwBrowserPermissionRequestDelegate::FromID(render_process_id,
+ render_view_id);
+ if (!delegate)
+ return;
+ switch (permission) {
+ case content::PERMISSION_GEOLOCATION:
+ delegate->CancelGeolocationPermissionRequests(origin);
+ break;
+ case content::PERMISSION_PROTECTED_MEDIA:
+ delegate->CancelProtectedMediaIdentifierPermissionRequests(origin);
+ break;
+ case content::PERMISSION_MIDI_SYSEX:
+ case content::PERMISSION_NOTIFICATIONS:
+ case content::PERMISSION_PUSH_MESSAGING:
+ NOTIMPLEMENTED() << "CancelPermission not implemented for " << permission;
+ break;
+ case content::PERMISSION_NUM:
+ NOTREACHED() << "Invalid CancelPermission for " << permission;
+ break;
+ }
}
bool AwContentBrowserClient::CanCreateWindow(
bool opener_suppressed,
content::ResourceContext* context,
int render_process_id,
- bool is_guest,
int opener_id,
bool* no_javascript_access) {
// We unconditionally allow popup windows at this stage and will give
return true;
}
-std::string AwContentBrowserClient::GetWorkerProcessTitle(const GURL& url,
- content::ResourceContext* context) {
- NOTREACHED() << "Android WebView does not yet support web workers.";
- return std::string();
-}
-
-
void AwContentBrowserClient::ResourceDispatcherHostCreated() {
AwResourceDispatcherHostDelegate::ResourceDispatcherHostCreated();
}
net::NetLog* AwContentBrowserClient::GetNetLog() {
- // TODO(boliu): Implement AwNetLog.
- return NULL;
+ return browser_context_->GetAwURLRequestContext()->GetNetLog();
}
content::AccessTokenStore* AwContentBrowserClient::CreateAccessTokenStore() {
return false;
}
-void AwContentBrowserClient::UpdateInspectorSetting(
- content::RenderViewHost* rvh,
- const std::string& key,
- const std::string& value) {
- // TODO(boliu): Implement persisting inspector settings.
- NOTIMPLEMENTED();
-}
-
void AwContentBrowserClient::ClearCache(content::RenderViewHost* rvh) {
RemoveHttpDiskCache(rvh->GetProcess()->GetBrowserContext(),
rvh->GetProcess()->GetID());
return false;
}
-void AwContentBrowserClient::OverrideWebkitPrefs(content::RenderViewHost* rvh,
- const GURL& url,
- WebPreferences* web_prefs) {
+void AwContentBrowserClient::OverrideWebkitPrefs(
+ content::RenderViewHost* rvh,
+ const GURL& url,
+ content::WebPreferences* web_prefs) {
if (!preferences_populater_.get()) {
preferences_populater_ = make_scoped_ptr(native_factory_->
CreateWebPreferencesPopulater());
content::WebContents::FromRenderViewHost(rvh), web_prefs);
}
+#if defined(VIDEO_HOLE)
+content::ExternalVideoSurfaceContainer*
+AwContentBrowserClient::OverrideCreateExternalVideoSurfaceContainer(
+ content::WebContents* web_contents) {
+ return native_factory_->CreateExternalVideoSurfaceContainer(web_contents);
+}
+#endif
+
+content::DevToolsManagerDelegate*
+AwContentBrowserClient::GetDevToolsManagerDelegate() {
+ return new AwDevToolsManagerDelegate();
+}
+
} // namespace android_webview