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

Side by Side Diff: extensions/browser/guest_view/web_view/web_view_guest.cc

Issue 764643002: Remove WebViewKey in rules registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits. Created 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/guest_view/web_view/web_view_guest.h" 5 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
(...skipping 12 matching lines...) Expand all
23 #include "content/public/browser/site_instance.h" 23 #include "content/public/browser/site_instance.h"
24 #include "content/public/browser/storage_partition.h" 24 #include "content/public/browser/storage_partition.h"
25 #include "content/public/browser/user_metrics.h" 25 #include "content/public/browser/user_metrics.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "content/public/browser/web_contents_delegate.h" 27 #include "content/public/browser/web_contents_delegate.h"
28 #include "content/public/common/media_stream_request.h" 28 #include "content/public/common/media_stream_request.h"
29 #include "content/public/common/page_zoom.h" 29 #include "content/public/common/page_zoom.h"
30 #include "content/public/common/result_codes.h" 30 #include "content/public/common/result_codes.h"
31 #include "content/public/common/stop_find_action.h" 31 #include "content/public/common/stop_find_action.h"
32 #include "content/public/common/url_constants.h" 32 #include "content/public/common/url_constants.h"
33 #include "extensions/browser/api/declarative/rules_registry_service.h"
33 #include "extensions/browser/api/extensions_api_client.h" 34 #include "extensions/browser/api/extensions_api_client.h"
34 #include "extensions/browser/api/web_request/web_request_api.h" 35 #include "extensions/browser/api/web_request/web_request_api.h"
35 #include "extensions/browser/api/web_view/web_view_internal_api.h" 36 #include "extensions/browser/api/web_view/web_view_internal_api.h"
36 #include "extensions/browser/extension_system.h" 37 #include "extensions/browser/extension_system.h"
37 #include "extensions/browser/guest_view/guest_view_manager.h" 38 #include "extensions/browser/guest_view/guest_view_manager.h"
38 #include "extensions/browser/guest_view/web_view/web_view_constants.h" 39 #include "extensions/browser/guest_view/web_view/web_view_constants.h"
39 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" 40 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
40 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" 41 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h"
41 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" 42 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
42 #include "extensions/common/constants.h" 43 #include "extensions/common/constants.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // The partition name is user supplied value, which we have encoded when the 174 // The partition name is user supplied value, which we have encoded when the
174 // URL was created, so it needs to be decoded. 175 // URL was created, so it needs to be decoded.
175 *partition_name = 176 *partition_name =
176 net::UnescapeURLComponent(site.query(), net::UnescapeRule::NORMAL); 177 net::UnescapeURLComponent(site.query(), net::UnescapeRule::NORMAL);
177 return true; 178 return true;
178 } 179 }
179 180
180 // static 181 // static
181 const char WebViewGuest::Type[] = "webview"; 182 const char WebViewGuest::Type[] = "webview";
182 183
184 typedef std::pair<int, int> WebViewKey;
185 typedef std::map<WebViewKey, int> WebViewKeyToIDMap;
186 static base::LazyInstance<WebViewKeyToIDMap> web_view_key_to_id_map =
187 LAZY_INSTANCE_INITIALIZER;
188
189 // static
190 int WebViewGuest::GetOrGenerateRulesRegistryID(
191 int embedder_process_id,
192 int webview_instance_id,
193 content::BrowserContext* browser_context) {
194 bool is_web_view = embedder_process_id && webview_instance_id;
195 if (!is_web_view)
196 return RulesRegistryService::kDefaultRulesRegistryID;
197
198 WebViewKey key = std::make_pair(embedder_process_id, webview_instance_id);
199 auto it = web_view_key_to_id_map.Get().find(key);
200 if (it != web_view_key_to_id_map.Get().end())
201 return it->second;
202
203 int rules_registry_id =
204 RulesRegistryService::Get(browser_context)->GetNextRulesRegistryID();
205 web_view_key_to_id_map.Get()[key] = rules_registry_id;
206 return rules_registry_id;
207 }
208
183 // static 209 // static
184 int WebViewGuest::GetViewInstanceId(WebContents* contents) { 210 int WebViewGuest::GetViewInstanceId(WebContents* contents) {
185 WebViewGuest* guest = FromWebContents(contents); 211 WebViewGuest* guest = FromWebContents(contents);
186 if (!guest) 212 if (!guest)
187 return guestview::kInstanceIDNone; 213 return guestview::kInstanceIDNone;
188 214
189 return guest->view_instance_id(); 215 return guest->view_instance_id();
190 } 216 }
191 217
192 const char* WebViewGuest::GetAPINamespace() const { 218 const char* WebViewGuest::GetAPINamespace() const {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 void WebViewGuest::DidStopLoading() { 366 void WebViewGuest::DidStopLoading() {
341 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 367 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
342 DispatchEventToEmbedder( 368 DispatchEventToEmbedder(
343 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); 369 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass()));
344 } 370 }
345 371
346 void WebViewGuest::EmbedderWillBeDestroyed() { 372 void WebViewGuest::EmbedderWillBeDestroyed() {
347 if (web_view_guest_delegate_) 373 if (web_view_guest_delegate_)
348 web_view_guest_delegate_->OnEmbedderWillBeDestroyed(); 374 web_view_guest_delegate_->OnEmbedderWillBeDestroyed();
349 375
376 // Clean up rules registries for the webview.
377 RulesRegistryService::Get(browser_context())
378 ->RemoveRulesRegistriesByID(rules_registry_id_);
379 WebViewKey key(owner_render_process_id(), view_instance_id());
380 web_view_key_to_id_map.Get().erase(key);
381
350 content::BrowserThread::PostTask( 382 content::BrowserThread::PostTask(
351 content::BrowserThread::IO, 383 content::BrowserThread::IO,
352 FROM_HERE, 384 FROM_HERE,
353 base::Bind( 385 base::Bind(
354 &RemoveWebViewEventListenersOnIOThread, 386 &RemoveWebViewEventListenersOnIOThread,
355 browser_context(), 387 browser_context(),
356 embedder_extension_id(), 388 embedder_extension_id(),
357 owner_render_process_id(), 389 owner_render_process_id(),
358 view_instance_id())); 390 view_instance_id()));
359 } 391 }
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 content::StoragePartition::OriginMatcherFunction(), 693 content::StoragePartition::OriginMatcherFunction(),
662 remove_since, 694 remove_since,
663 base::Time::Now(), 695 base::Time::Now(),
664 callback); 696 callback);
665 return true; 697 return true;
666 } 698 }
667 699
668 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, 700 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context,
669 int guest_instance_id) 701 int guest_instance_id)
670 : GuestView<WebViewGuest>(browser_context, guest_instance_id), 702 : GuestView<WebViewGuest>(browser_context, guest_instance_id),
703 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID),
671 find_helper_(this), 704 find_helper_(this),
672 is_overriding_user_agent_(false), 705 is_overriding_user_agent_(false),
673 guest_opaque_(true), 706 guest_opaque_(true),
674 javascript_dialog_helper_(this), 707 javascript_dialog_helper_(this),
675 weak_ptr_factory_(this) { 708 weak_ptr_factory_(this) {
676 web_view_guest_delegate_.reset( 709 web_view_guest_delegate_.reset(
677 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); 710 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this));
678 } 711 }
679 712
680 WebViewGuest::~WebViewGuest() { 713 WebViewGuest::~WebViewGuest() {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 site_url, &partition_domain, &partition_id, &in_memory)) { 838 site_url, &partition_domain, &partition_id, &in_memory)) {
806 NOTREACHED(); 839 NOTREACHED();
807 return; 840 return;
808 } 841 }
809 842
810 WebViewRendererState::WebViewInfo web_view_info; 843 WebViewRendererState::WebViewInfo web_view_info;
811 web_view_info.embedder_process_id = owner_render_process_id(); 844 web_view_info.embedder_process_id = owner_render_process_id();
812 web_view_info.instance_id = view_instance_id(); 845 web_view_info.instance_id = view_instance_id();
813 web_view_info.partition_id = partition_id; 846 web_view_info.partition_id = partition_id;
814 web_view_info.embedder_extension_id = embedder_extension_id(); 847 web_view_info.embedder_extension_id = embedder_extension_id();
848 web_view_info.rules_registry_id = rules_registry_id_;
815 849
816 content::BrowserThread::PostTask( 850 content::BrowserThread::PostTask(
817 content::BrowserThread::IO, 851 content::BrowserThread::IO,
818 FROM_HERE, 852 FROM_HERE,
819 base::Bind(&WebViewRendererState::AddGuest, 853 base::Bind(&WebViewRendererState::AddGuest,
820 base::Unretained(WebViewRendererState::GetInstance()), 854 base::Unretained(WebViewRendererState::GetInstance()),
821 web_contents()->GetRenderProcessHost()->GetID(), 855 web_contents()->GetRenderProcessHost()->GetID(),
822 web_contents()->GetRoutingID(), 856 web_contents()->GetRoutingID(),
823 web_view_info)); 857 web_view_info));
824 } 858 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 bool user_gesture, 911 bool user_gesture,
878 bool last_unlocked_by_target, 912 bool last_unlocked_by_target,
879 const base::Callback<void(bool)>& callback) { 913 const base::Callback<void(bool)>& callback) {
880 web_view_permission_helper_->RequestPointerLockPermission( 914 web_view_permission_helper_->RequestPointerLockPermission(
881 user_gesture, 915 user_gesture,
882 last_unlocked_by_target, 916 last_unlocked_by_target,
883 callback); 917 callback);
884 } 918 }
885 919
886 void WebViewGuest::WillAttachToEmbedder() { 920 void WebViewGuest::WillAttachToEmbedder() {
921 rules_registry_id_ = GetOrGenerateRulesRegistryID(
922 owner_render_process_id(), view_instance_id(), browser_context());
923
887 // We must install the mapping from guests to WebViews prior to resuming 924 // We must install the mapping from guests to WebViews prior to resuming
888 // suspended resource loads so that the WebRequest API will catch resource 925 // suspended resource loads so that the WebRequest API will catch resource
889 // requests. 926 // requests.
890 PushWebViewStateToIOThread(); 927 PushWebViewStateToIOThread();
891 } 928 }
892 929
893 content::JavaScriptDialogManager* WebViewGuest::GetJavaScriptDialogManager( 930 content::JavaScriptDialogManager* WebViewGuest::GetJavaScriptDialogManager(
894 WebContents* source) { 931 WebContents* source) {
895 return &javascript_dialog_helper_; 932 return &javascript_dialog_helper_;
896 } 933 }
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 WebViewGuest* guest = 1256 WebViewGuest* guest =
1220 WebViewGuest::From(owner_render_process_id(), new_window_instance_id); 1257 WebViewGuest::From(owner_render_process_id(), new_window_instance_id);
1221 if (!guest) 1258 if (!guest)
1222 return; 1259 return;
1223 1260
1224 if (!allow) 1261 if (!allow)
1225 guest->Destroy(); 1262 guest->Destroy();
1226 } 1263 }
1227 1264
1228 } // namespace extensions 1265 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698