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

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: Clean up. 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 ->RemoveRulesRegistry(rules_registry_id_);
379 int embedder_process_id =
380 embedder_web_contents()->GetRenderProcessHost()->GetID();
381 WebViewKey key(embedder_process_id, view_instance_id());
Fady Samuel 2014/11/28 16:39:30 nit: embedder_render_process_id()
Xi Han 2014/11/28 17:26:38 Done.
382 web_view_key_to_id_map.Get().erase(key);
383
350 content::BrowserThread::PostTask( 384 content::BrowserThread::PostTask(
351 content::BrowserThread::IO, 385 content::BrowserThread::IO,
352 FROM_HERE, 386 FROM_HERE,
353 base::Bind( 387 base::Bind(
354 &RemoveWebViewEventListenersOnIOThread, 388 &RemoveWebViewEventListenersOnIOThread,
355 browser_context(), 389 browser_context(),
356 embedder_extension_id(), 390 embedder_extension_id(),
357 embedder_render_process_id(), 391 embedder_render_process_id(),
358 view_instance_id())); 392 view_instance_id()));
359 } 393 }
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 content::StoragePartition::OriginMatcherFunction(), 695 content::StoragePartition::OriginMatcherFunction(),
662 remove_since, 696 remove_since,
663 base::Time::Now(), 697 base::Time::Now(),
664 callback); 698 callback);
665 return true; 699 return true;
666 } 700 }
667 701
668 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, 702 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context,
669 int guest_instance_id) 703 int guest_instance_id)
670 : GuestView<WebViewGuest>(browser_context, guest_instance_id), 704 : GuestView<WebViewGuest>(browser_context, guest_instance_id),
705 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID),
671 find_helper_(this), 706 find_helper_(this),
672 is_overriding_user_agent_(false), 707 is_overriding_user_agent_(false),
673 guest_opaque_(true), 708 guest_opaque_(true),
674 javascript_dialog_helper_(this), 709 javascript_dialog_helper_(this),
675 weak_ptr_factory_(this) { 710 weak_ptr_factory_(this) {
676 web_view_guest_delegate_.reset( 711 web_view_guest_delegate_.reset(
677 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); 712 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this));
678 } 713 }
679 714
680 WebViewGuest::~WebViewGuest() { 715 WebViewGuest::~WebViewGuest() {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 site_url, &partition_domain, &partition_id, &in_memory)) { 840 site_url, &partition_domain, &partition_id, &in_memory)) {
806 NOTREACHED(); 841 NOTREACHED();
807 return; 842 return;
808 } 843 }
809 844
810 WebViewRendererState::WebViewInfo web_view_info; 845 WebViewRendererState::WebViewInfo web_view_info;
811 web_view_info.embedder_process_id = embedder_render_process_id(); 846 web_view_info.embedder_process_id = embedder_render_process_id();
812 web_view_info.instance_id = view_instance_id(); 847 web_view_info.instance_id = view_instance_id();
813 web_view_info.partition_id = partition_id; 848 web_view_info.partition_id = partition_id;
814 web_view_info.embedder_extension_id = embedder_extension_id(); 849 web_view_info.embedder_extension_id = embedder_extension_id();
850 web_view_info.rules_registry_id = rules_registry_id_;
815 851
816 content::BrowserThread::PostTask( 852 content::BrowserThread::PostTask(
817 content::BrowserThread::IO, 853 content::BrowserThread::IO,
818 FROM_HERE, 854 FROM_HERE,
819 base::Bind(&WebViewRendererState::AddGuest, 855 base::Bind(&WebViewRendererState::AddGuest,
820 base::Unretained(WebViewRendererState::GetInstance()), 856 base::Unretained(WebViewRendererState::GetInstance()),
821 web_contents()->GetRenderProcessHost()->GetID(), 857 web_contents()->GetRenderProcessHost()->GetID(),
822 web_contents()->GetRoutingID(), 858 web_contents()->GetRoutingID(),
823 web_view_info)); 859 web_view_info));
824 } 860 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 bool user_gesture, 913 bool user_gesture,
878 bool last_unlocked_by_target, 914 bool last_unlocked_by_target,
879 const base::Callback<void(bool)>& callback) { 915 const base::Callback<void(bool)>& callback) {
880 web_view_permission_helper_->RequestPointerLockPermission( 916 web_view_permission_helper_->RequestPointerLockPermission(
881 user_gesture, 917 user_gesture,
882 last_unlocked_by_target, 918 last_unlocked_by_target,
883 callback); 919 callback);
884 } 920 }
885 921
886 void WebViewGuest::WillAttachToEmbedder() { 922 void WebViewGuest::WillAttachToEmbedder() {
923 int embedder_process_id =
924 embedder_web_contents()->GetRenderProcessHost()->GetID();
925 rules_registry_id_ = GetOrGenerateRulesRegistryID(
926 embedder_process_id, view_instance_id(), browser_context());
Fady Samuel 2014/11/28 16:39:30 nit: use embedder_render_process_id()
Xi Han 2014/11/28 17:26:38 Done.
927
887 // We must install the mapping from guests to WebViews prior to resuming 928 // We must install the mapping from guests to WebViews prior to resuming
888 // suspended resource loads so that the WebRequest API will catch resource 929 // suspended resource loads so that the WebRequest API will catch resource
889 // requests. 930 // requests.
890 PushWebViewStateToIOThread(); 931 PushWebViewStateToIOThread();
891 } 932 }
892 933
893 content::JavaScriptDialogManager* WebViewGuest::GetJavaScriptDialogManager( 934 content::JavaScriptDialogManager* WebViewGuest::GetJavaScriptDialogManager(
894 WebContents* source) { 935 WebContents* source) {
895 return &javascript_dialog_helper_; 936 return &javascript_dialog_helper_;
896 } 937 }
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 WebViewGuest* guest = 1260 WebViewGuest* guest =
1220 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1261 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1221 if (!guest) 1262 if (!guest)
1222 return; 1263 return;
1223 1264
1224 if (!allow) 1265 if (!allow)
1225 guest->Destroy(); 1266 guest->Destroy();
1226 } 1267 }
1227 1268
1228 } // namespace extensions 1269 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698