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

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: addressed code review Created 7 years, 2 months 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_info.h" 30 #include "net/ssl/ssl_info.h"
28 #include "ui/base/l10n/l10n_util_android.h" 31 #include "ui/base/l10n/l10n_util_android.h"
29 #include "ui/base/resource/resource_bundle.h" 32 #include "ui/base/resource/resource_bundle.h"
30 #include "webkit/common/webpreferences.h" 33 #include "webkit/common/webpreferences.h"
31 34
35 using content::BrowserThread;
36
32 namespace android_webview { 37 namespace android_webview {
33 namespace { 38 namespace {
34 39
40 // TODO(sgurun) move this to its own file.
mkosiba (inactive) 2013/10/17 10:27:45 any reason not to do this now?
sgurun-gerrit only 2013/12/06 00:17:48 Given the very temporary nature of these changes,
41 // This class filters out incoming aw_contents related IPC messages for the
42 // renderer process on the IPC thread.
43 class AwContentsMessageFilter : public content::BrowserMessageFilter {
44 public:
45 AwContentsMessageFilter(int process_id);
46
47 // BrowserMessageFilter methods
48 virtual void OverrideThreadForMessage(
49 const IPC::Message& message,
50 BrowserThread::ID* thread) OVERRIDE;
51 virtual bool OnMessageReceived(
52 const IPC::Message& message,
53 bool* message_was_ok) OVERRIDE;
54
55 void OnShouldOverrideUrlLoading(int routing_id,
56 const base::string16& url,
57 bool* ignore_navigation);
58
59 private:
60 virtual ~AwContentsMessageFilter();
61
62 int process_id_;
63
64 DISALLOW_COPY_AND_ASSIGN(AwContentsMessageFilter);
65 };
66
35 class AwAccessTokenStore : public content::AccessTokenStore { 67 class AwAccessTokenStore : public content::AccessTokenStore {
36 public: 68 public:
37 AwAccessTokenStore() { } 69 AwAccessTokenStore() { }
38 70
39 // content::AccessTokenStore implementation 71 // content::AccessTokenStore implementation
40 virtual void LoadAccessTokens( 72 virtual void LoadAccessTokens(
41 const LoadAccessTokensCallbackType& request) OVERRIDE { 73 const LoadAccessTokensCallbackType& request) OVERRIDE {
42 AccessTokenStore::AccessTokenSet access_token_set; 74 AccessTokenStore::AccessTokenSet access_token_set;
43 // AccessTokenSet and net::URLRequestContextGetter not used on Android, 75 // AccessTokenSet and net::URLRequestContextGetter not used on Android,
44 // but Run needs to be called to finish the geolocation setup. 76 // but Run needs to be called to finish the geolocation setup.
45 request.Run(access_token_set, NULL); 77 request.Run(access_token_set, NULL);
46 } 78 }
47 virtual void SaveAccessToken(const GURL& server_url, 79 virtual void SaveAccessToken(const GURL& server_url,
48 const string16& access_token) OVERRIDE { } 80 const string16& access_token) OVERRIDE { }
49 81
50 private: 82 private:
51 virtual ~AwAccessTokenStore() { } 83 virtual ~AwAccessTokenStore() { }
52 84
53 DISALLOW_COPY_AND_ASSIGN(AwAccessTokenStore); 85 DISALLOW_COPY_AND_ASSIGN(AwAccessTokenStore);
54 }; 86 };
55 87
56 } 88 }
57 89
90 AwContentsMessageFilter::AwContentsMessageFilter(int process_id)
91 : process_id_(process_id) {
92 }
93
94 AwContentsMessageFilter::~AwContentsMessageFilter() {
95 }
96
97 void AwContentsMessageFilter::OverrideThreadForMessage(
98 const IPC::Message& message, BrowserThread::ID* thread) {
99 if (message.type() == AwViewHostMsg_ShouldOverrideUrlLoading::ID) {
100 *thread = BrowserThread::UI;
101 }
102 }
103
104 bool AwContentsMessageFilter::OnMessageReceived(const IPC::Message& message,
105 bool* message_was_ok) {
106 bool handled = true;
107 IPC_BEGIN_MESSAGE_MAP_EX(AwContentsMessageFilter, message, *message_was_ok)
108 IPC_MESSAGE_HANDLER(AwViewHostMsg_ShouldOverrideUrlLoading,
109 OnShouldOverrideUrlLoading)
110 IPC_MESSAGE_UNHANDLED(handled = false)
111 IPC_END_MESSAGE_MAP()
112 return handled;
113 }
114
115 void AwContentsMessageFilter::OnShouldOverrideUrlLoading(
116 int routing_id,
117 const base::string16& url,
118 bool* ignore_navigation) {
119 *ignore_navigation = false;
120 AwContentsClientBridgeBase* client =
121 AwContentsClientBridgeBase::FromID(process_id_, routing_id);
122 if (client) {
123 *ignore_navigation = client->ShouldOverrideUrlLoading(url);
124 } else {
125 LOG(WARNING) << "Failed to find the associated render view host for url: "
126 << url;
127 }
128 }
129
58 std::string AwContentBrowserClient::GetAcceptLangsImpl() { 130 std::string AwContentBrowserClient::GetAcceptLangsImpl() {
59 // Start with the currnet locale. 131 // Start with the currnet locale.
60 std::string langs = l10n_util::GetDefaultLocale(); 132 std::string langs = l10n_util::GetDefaultLocale();
61 133
62 // If we're not en-US, add in en-US which will be 134 // If we're not en-US, add in en-US which will be
63 // used with a lower q-value. 135 // used with a lower q-value.
64 if (StringToLowerASCII(langs) != "en-us") { 136 if (StringToLowerASCII(langs) != "en-us") {
65 langs += ",en-US"; 137 langs += ",en-US";
66 } 138 }
67 return langs; 139 return langs;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // really does need that priviledge. Check here to ensure we rethink this 186 // really does need that priviledge. Check here to ensure we rethink this
115 // when the time comes. See crbug.com/156062. 187 // when the time comes. See crbug.com/156062.
116 CHECK(content::RenderProcessHost::run_renderer_in_process()); 188 CHECK(content::RenderProcessHost::run_renderer_in_process());
117 189
118 // Grant content: and file: scheme to the whole process, since we impose 190 // Grant content: and file: scheme to the whole process, since we impose
119 // per-view access checks. 191 // per-view access checks.
120 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( 192 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
121 host->GetID(), android_webview::kContentScheme); 193 host->GetID(), android_webview::kContentScheme);
122 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( 194 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
123 host->GetID(), chrome::kFileScheme); 195 host->GetID(), chrome::kFileScheme);
196
197 host->AddFilter(new AwContentsMessageFilter(host->GetID()));
124 } 198 }
125 199
126 net::URLRequestContextGetter* 200 net::URLRequestContextGetter*
127 AwContentBrowserClient::CreateRequestContext( 201 AwContentBrowserClient::CreateRequestContext(
128 content::BrowserContext* browser_context, 202 content::BrowserContext* browser_context,
129 content::ProtocolHandlerMap* protocol_handlers) { 203 content::ProtocolHandlerMap* protocol_handlers) {
130 DCHECK(browser_context_.get() == browser_context); 204 DCHECK(browser_context_.get() == browser_context);
131 return browser_context_->CreateRequestContext(protocol_handlers); 205 return browser_context_->CreateRequestContext(protocol_handlers);
132 } 206 }
133 207
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 WebPreferences* web_prefs) { 469 WebPreferences* web_prefs) {
396 if (!preferences_populater_.get()) { 470 if (!preferences_populater_.get()) {
397 preferences_populater_ = make_scoped_ptr(native_factory_-> 471 preferences_populater_ = make_scoped_ptr(native_factory_->
398 CreateWebPreferencesPopulater()); 472 CreateWebPreferencesPopulater());
399 } 473 }
400 preferences_populater_->PopulateFor( 474 preferences_populater_->PopulateFor(
401 content::WebContents::FromRenderViewHost(rvh), web_prefs); 475 content::WebContents::FromRenderViewHost(rvh), web_prefs);
402 } 476 }
403 477
404 } // namespace android_webview 478 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698