Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: android_webview/browser/aw_content_browser_client.cc

Issue 24228003: Upstream ShouldOverrideUrlLoading changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added a test Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/browser/aw_content_browser_client.h" 5 #include "android_webview/browser/aw_content_browser_client.h"
6 6
7 #include "android_webview/browser/aw_browser_context.h" 7 #include "android_webview/browser/aw_browser_context.h"
8 #include "android_webview/browser/aw_browser_main_parts.h" 8 #include "android_webview/browser/aw_browser_main_parts.h"
9 #include "android_webview/browser/aw_contents_client_bridge_base.h" 9 #include "android_webview/browser/aw_contents_client_bridge_base.h"
10 #include "android_webview/browser/aw_cookie_access_policy.h" 10 #include "android_webview/browser/aw_cookie_access_policy.h"
11 #include "android_webview/browser/aw_quota_permission_context.h" 11 #include "android_webview/browser/aw_quota_permission_context.h"
12 #include "android_webview/browser/aw_web_preferences_populater.h" 12 #include "android_webview/browser/aw_web_preferences_populater.h"
13 #include "android_webview/browser/jni_dependency_factory.h" 13 #include "android_webview/browser/jni_dependency_factory.h"
14 #include "android_webview/browser/net_disk_cache_remover.h" 14 #include "android_webview/browser/net_disk_cache_remover.h"
15 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele gate.h" 15 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele gate.h"
16 #include "android_webview/common/render_view_messages.h"
16 #include "android_webview/common/url_constants.h" 17 #include "android_webview/common/url_constants.h"
17 #include "base/base_paths_android.h" 18 #include "base/base_paths_android.h"
18 #include "base/path_service.h" 19 #include "base/path_service.h"
19 #include "content/public/browser/access_token_store.h" 20 #include "content/public/browser/access_token_store.h"
21 #include "content/public/browser/browser_message_filter.h"
22 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/child_process_security_policy.h" 23 #include "content/public/browser/child_process_security_policy.h"
21 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/render_view_host.h" 25 #include "content/public/browser/render_view_host.h"
23 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
24 #include "content/public/common/url_constants.h" 27 #include "content/public/common/url_constants.h"
25 #include "grit/ui_resources.h" 28 #include "grit/ui_resources.h"
26 #include "net/android/network_library.h" 29 #include "net/android/network_library.h"
27 #include "net/ssl/ssl_cert_request_info.h" 30 #include "net/ssl/ssl_cert_request_info.h"
28 #include "net/ssl/ssl_info.h" 31 #include "net/ssl/ssl_info.h"
29 #include "ui/base/l10n/l10n_util_android.h" 32 #include "ui/base/l10n/l10n_util_android.h"
30 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
31 #include "webkit/common/webpreferences.h" 34 #include "webkit/common/webpreferences.h"
32 35
36 using content::BrowserThread;
37
33 namespace android_webview { 38 namespace android_webview {
34 namespace { 39 namespace {
35 40
41 // TODO(sgurun) move this to its own file.
42 // This class filters out incoming aw_contents related IPC messages for the
43 // renderer process on the IPC thread.
44 class AwContentsMessageFilter : public content::BrowserMessageFilter {
45 public:
46 AwContentsMessageFilter(int process_id);
boliu 2013/12/06 20:28:23 need explicit keyword for 1-arg constructor
sgurun-gerrit only 2013/12/07 00:11:07 Done.
47
48 // BrowserMessageFilter methods
boliu 2013/12/06 20:28:23 nit: period
sgurun-gerrit only 2013/12/07 00:11:07 Done.
49 virtual void OverrideThreadForMessage(
50 const IPC::Message& message,
51 BrowserThread::ID* thread) OVERRIDE;
52 virtual bool OnMessageReceived(
53 const IPC::Message& message,
54 bool* message_was_ok) OVERRIDE;
55
56 void OnShouldOverrideUrlLoading(int routing_id,
57 const base::string16& url,
58 bool* ignore_navigation);
59
60 private:
61 virtual ~AwContentsMessageFilter();
62
63 int process_id_;
64
65 DISALLOW_COPY_AND_ASSIGN(AwContentsMessageFilter);
66 };
67
36 class AwAccessTokenStore : public content::AccessTokenStore { 68 class AwAccessTokenStore : public content::AccessTokenStore {
37 public: 69 public:
38 AwAccessTokenStore() { } 70 AwAccessTokenStore() { }
39 71
40 // content::AccessTokenStore implementation 72 // content::AccessTokenStore implementation
41 virtual void LoadAccessTokens( 73 virtual void LoadAccessTokens(
42 const LoadAccessTokensCallbackType& request) OVERRIDE { 74 const LoadAccessTokensCallbackType& request) OVERRIDE {
43 AccessTokenStore::AccessTokenSet access_token_set; 75 AccessTokenStore::AccessTokenSet access_token_set;
44 // AccessTokenSet and net::URLRequestContextGetter not used on Android, 76 // AccessTokenSet and net::URLRequestContextGetter not used on Android,
45 // but Run needs to be called to finish the geolocation setup. 77 // but Run needs to be called to finish the geolocation setup.
46 request.Run(access_token_set, NULL); 78 request.Run(access_token_set, NULL);
47 } 79 }
48 virtual void SaveAccessToken(const GURL& server_url, 80 virtual void SaveAccessToken(const GURL& server_url,
49 const string16& access_token) OVERRIDE { } 81 const string16& access_token) OVERRIDE { }
50 82
51 private: 83 private:
52 virtual ~AwAccessTokenStore() { } 84 virtual ~AwAccessTokenStore() { }
53 85
54 DISALLOW_COPY_AND_ASSIGN(AwAccessTokenStore); 86 DISALLOW_COPY_AND_ASSIGN(AwAccessTokenStore);
55 }; 87 };
56 88
57 } 89 }
58 90
91 AwContentsMessageFilter::AwContentsMessageFilter(int process_id)
boliu 2013/12/06 20:28:23 nit: why not keep implementation next to the class
sgurun-gerrit only 2013/12/07 00:11:07 Done.
92 : process_id_(process_id) {
93 }
94
95 AwContentsMessageFilter::~AwContentsMessageFilter() {
96 }
97
98 void AwContentsMessageFilter::OverrideThreadForMessage(
99 const IPC::Message& message, BrowserThread::ID* thread) {
100 if (message.type() == AwViewHostMsg_ShouldOverrideUrlLoading::ID) {
101 *thread = BrowserThread::UI;
102 }
103 }
104
105 bool AwContentsMessageFilter::OnMessageReceived(const IPC::Message& message,
106 bool* message_was_ok) {
107 bool handled = true;
108 IPC_BEGIN_MESSAGE_MAP_EX(AwContentsMessageFilter, message, *message_was_ok)
109 IPC_MESSAGE_HANDLER(AwViewHostMsg_ShouldOverrideUrlLoading,
110 OnShouldOverrideUrlLoading)
111 IPC_MESSAGE_UNHANDLED(handled = false)
112 IPC_END_MESSAGE_MAP()
113 return handled;
114 }
115
116 void AwContentsMessageFilter::OnShouldOverrideUrlLoading(
117 int routing_id,
118 const base::string16& url,
119 bool* ignore_navigation) {
boliu 2013/12/06 20:28:23 DCHECK this is running on ui thread
sgurun-gerrit only 2013/12/07 00:11:07 Done.
120 *ignore_navigation = false;
121 AwContentsClientBridgeBase* client =
122 AwContentsClientBridgeBase::FromID(process_id_, routing_id);
123 if (client) {
124 *ignore_navigation = client->ShouldOverrideUrlLoading(url);
125 } else {
126 LOG(WARNING) << "Failed to find the associated render view host for url: "
127 << url;
128 }
129 }
130
59 std::string AwContentBrowserClient::GetAcceptLangsImpl() { 131 std::string AwContentBrowserClient::GetAcceptLangsImpl() {
60 // Start with the currnet locale. 132 // Start with the currnet locale.
61 std::string langs = l10n_util::GetDefaultLocale(); 133 std::string langs = l10n_util::GetDefaultLocale();
62 134
63 // If we're not en-US, add in en-US which will be 135 // If we're not en-US, add in en-US which will be
64 // used with a lower q-value. 136 // used with a lower q-value.
65 if (StringToLowerASCII(langs) != "en-us") { 137 if (StringToLowerASCII(langs) != "en-us") {
66 langs += ",en-US"; 138 langs += ",en-US";
67 } 139 }
68 return langs; 140 return langs;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // really does need that priviledge. Check here to ensure we rethink this 187 // really does need that priviledge. Check here to ensure we rethink this
116 // when the time comes. See crbug.com/156062. 188 // when the time comes. See crbug.com/156062.
117 CHECK(content::RenderProcessHost::run_renderer_in_process()); 189 CHECK(content::RenderProcessHost::run_renderer_in_process());
118 190
119 // Grant content: and file: scheme to the whole process, since we impose 191 // Grant content: and file: scheme to the whole process, since we impose
120 // per-view access checks. 192 // per-view access checks.
121 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( 193 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
122 host->GetID(), android_webview::kContentScheme); 194 host->GetID(), android_webview::kContentScheme);
123 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( 195 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
124 host->GetID(), chrome::kFileScheme); 196 host->GetID(), chrome::kFileScheme);
197
198 host->AddFilter(new AwContentsMessageFilter(host->GetID()));
125 } 199 }
126 200
127 net::URLRequestContextGetter* 201 net::URLRequestContextGetter*
128 AwContentBrowserClient::CreateRequestContext( 202 AwContentBrowserClient::CreateRequestContext(
129 content::BrowserContext* browser_context, 203 content::BrowserContext* browser_context,
130 content::ProtocolHandlerMap* protocol_handlers) { 204 content::ProtocolHandlerMap* protocol_handlers) {
131 DCHECK(browser_context_.get() == browser_context); 205 DCHECK(browser_context_.get() == browser_context);
132 return browser_context_->CreateRequestContext(protocol_handlers); 206 return browser_context_->CreateRequestContext(protocol_handlers);
133 } 207 }
134 208
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 WebPreferences* web_prefs) { 482 WebPreferences* web_prefs) {
409 if (!preferences_populater_.get()) { 483 if (!preferences_populater_.get()) {
410 preferences_populater_ = make_scoped_ptr(native_factory_-> 484 preferences_populater_ = make_scoped_ptr(native_factory_->
411 CreateWebPreferencesPopulater()); 485 CreateWebPreferencesPopulater());
412 } 486 }
413 preferences_populater_->PopulateFor( 487 preferences_populater_->PopulateFor(
414 content::WebContents::FromRenderViewHost(rvh), web_prefs); 488 content::WebContents::FromRenderViewHost(rvh), web_prefs);
415 } 489 }
416 490
417 } // namespace android_webview 491 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698