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

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

Issue 1102173002: Move GuestView layer in browser to components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Jochen's comment + GuestViewBase cleanup Created 5 years, 7 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 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 "components/browsing_data/storage_partition_http_cache_data_remover.h" 10 #include "components/browsing_data/storage_partition_http_cache_data_remover.h"
11 #include "components/guest_view/browser/guest_view_event.h"
12 #include "components/guest_view/browser/guest_view_manager.h"
13 #include "components/guest_view/common/guest_view_constants.h"
11 #include "components/web_cache/browser/web_cache_manager.h" 14 #include "components/web_cache/browser/web_cache_manager.h"
12 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/child_process_security_policy.h" 17 #include "content/public/browser/child_process_security_policy.h"
15 #include "content/public/browser/native_web_keyboard_event.h" 18 #include "content/public/browser/native_web_keyboard_event.h"
16 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
17 #include "content/public/browser/notification_details.h" 20 #include "content/public/browser/notification_details.h"
18 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/notification_source.h" 22 #include "content/public/browser/notification_source.h"
20 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.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/render_widget_host_view.h" 26 #include "content/public/browser/render_widget_host_view.h"
24 #include "content/public/browser/resource_request_details.h" 27 #include "content/public/browser/resource_request_details.h"
25 #include "content/public/browser/site_instance.h" 28 #include "content/public/browser/site_instance.h"
26 #include "content/public/browser/storage_partition.h" 29 #include "content/public/browser/storage_partition.h"
27 #include "content/public/browser/user_metrics.h" 30 #include "content/public/browser/user_metrics.h"
28 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
29 #include "content/public/browser/web_contents_delegate.h" 32 #include "content/public/browser/web_contents_delegate.h"
30 #include "content/public/common/media_stream_request.h" 33 #include "content/public/common/media_stream_request.h"
31 #include "content/public/common/page_zoom.h" 34 #include "content/public/common/page_zoom.h"
32 #include "content/public/common/result_codes.h" 35 #include "content/public/common/result_codes.h"
33 #include "content/public/common/stop_find_action.h" 36 #include "content/public/common/stop_find_action.h"
34 #include "content/public/common/url_constants.h" 37 #include "content/public/common/url_constants.h"
35 #include "extensions/browser/api/declarative/rules_registry_service.h" 38 #include "extensions/browser/api/declarative/rules_registry_service.h"
36 #include "extensions/browser/api/extensions_api_client.h" 39 #include "extensions/browser/api/extensions_api_client.h"
37 #include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h" 40 #include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h"
38 #include "extensions/browser/api/web_request/web_request_api.h" 41 #include "extensions/browser/api/web_request/web_request_api.h"
39 #include "extensions/browser/extension_system.h" 42 #include "extensions/browser/extension_system.h"
40 #include "extensions/browser/guest_view/guest_view_event.h"
41 #include "extensions/browser/guest_view/guest_view_manager.h"
42 #include "extensions/browser/guest_view/web_view/web_view_constants.h" 43 #include "extensions/browser/guest_view/web_view/web_view_constants.h"
43 #include "extensions/browser/guest_view/web_view/web_view_content_script_manager .h" 44 #include "extensions/browser/guest_view/web_view/web_view_content_script_manager .h"
44 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" 45 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
45 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" 46 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h"
46 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" 47 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
47 #include "extensions/common/constants.h" 48 #include "extensions/common/constants.h"
48 #include "extensions/common/extension_messages.h" 49 #include "extensions/common/extension_messages.h"
49 #include "extensions/common/guest_view/guest_view_constants.h"
50 #include "extensions/strings/grit/extensions_strings.h" 50 #include "extensions/strings/grit/extensions_strings.h"
51 #include "ipc/ipc_message_macros.h" 51 #include "ipc/ipc_message_macros.h"
52 #include "net/base/escape.h" 52 #include "net/base/escape.h"
53 #include "net/base/net_errors.h" 53 #include "net/base/net_errors.h"
54 #include "ui/base/models/simple_menu_model.h" 54 #include "ui/base/models/simple_menu_model.h"
55 #include "url/url_constants.h" 55 #include "url/url_constants.h"
56 56
57 using base::UserMetricsAction; 57 using base::UserMetricsAction;
58 using content::RenderFrameHost; 58 using content::RenderFrameHost;
59 using content::ResourceType; 59 using content::ResourceType;
60 using content::StoragePartition; 60 using content::StoragePartition;
61 using content::WebContents; 61 using content::WebContents;
62 using guest_view::GuestViewBase;
63 using guest_view::GuestViewEvent;
64 using guest_view::GuestViewManager;
62 using ui_zoom::ZoomController; 65 using ui_zoom::ZoomController;
63 66
64 namespace extensions { 67 namespace extensions {
65 68
66 namespace { 69 namespace {
67 70
68 // Returns storage partition removal mask from web_view clearData mask. Note 71 // Returns storage partition removal mask from web_view clearData mask. Note
69 // that storage partition mask is a subset of webview's data removal mask. 72 // that storage partition mask is a subset of webview's data removal mask.
70 uint32 GetStoragePartitionRemovalMask(uint32 web_view_removal_mask) { 73 uint32 GetStoragePartitionRemovalMask(uint32 web_view_removal_mask) {
71 uint32 mask = 0; 74 uint32 mask = 0;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 RulesRegistryService::Get(rph->GetBrowserContext())-> 241 RulesRegistryService::Get(rph->GetBrowserContext())->
239 GetNextRulesRegistryID(); 242 GetNextRulesRegistryID();
240 web_view_key_to_id_map.Get()[key] = rules_registry_id; 243 web_view_key_to_id_map.Get()[key] = rules_registry_id;
241 return rules_registry_id; 244 return rules_registry_id;
242 } 245 }
243 246
244 // static 247 // static
245 int WebViewGuest::GetViewInstanceId(WebContents* contents) { 248 int WebViewGuest::GetViewInstanceId(WebContents* contents) {
246 auto guest = FromWebContents(contents); 249 auto guest = FromWebContents(contents);
247 if (!guest) 250 if (!guest)
248 return guestview::kInstanceIDNone; 251 return guest_view::kInstanceIDNone;
249 252
250 return guest->view_instance_id(); 253 return guest->view_instance_id();
251 } 254 }
252 255
253 bool WebViewGuest::CanRunInDetachedState() const { 256 bool WebViewGuest::CanRunInDetachedState() const {
254 return true; 257 return true;
255 } 258 }
256 259
257 void WebViewGuest::CreateWebContents( 260 void WebViewGuest::CreateWebContents(
258 const base::DictionaryValue& create_params, 261 const base::DictionaryValue& create_params,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 params.guest_delegate = this; 306 params.guest_delegate = this;
304 callback.Run(WebContents::Create(params)); 307 callback.Run(WebContents::Create(params));
305 } 308 }
306 309
307 void WebViewGuest::DidAttachToEmbedder() { 310 void WebViewGuest::DidAttachToEmbedder() {
308 ApplyAttributes(*attach_params()); 311 ApplyAttributes(*attach_params());
309 } 312 }
310 313
311 void WebViewGuest::DidDropLink(const GURL& url) { 314 void WebViewGuest::DidDropLink(const GURL& url) {
312 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 315 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
313 args->SetString(guestview::kUrl, url.spec()); 316 args->SetString(guest_view::kUrl, url.spec());
314 DispatchEventToView( 317 DispatchEventToView(
315 new GuestViewEvent(webview::kEventDropLink, args.Pass())); 318 new GuestViewEvent(webview::kEventDropLink, args.Pass()));
316 } 319 }
317 320
318 void WebViewGuest::DidInitialize(const base::DictionaryValue& create_params) { 321 void WebViewGuest::DidInitialize(const base::DictionaryValue& create_params) {
319 script_executor_.reset( 322 script_executor_.reset(
320 new ScriptExecutor(web_contents(), &script_observers_)); 323 new ScriptExecutor(web_contents(), &script_observers_));
321 324
322 notification_registrar_.Add(this, 325 notification_registrar_.Add(this,
323 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 326 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 } 538 }
536 539
537 bool WebViewGuest::PreHandleGestureEvent(content::WebContents* source, 540 bool WebViewGuest::PreHandleGestureEvent(content::WebContents* source,
538 const blink::WebGestureEvent& event) { 541 const blink::WebGestureEvent& event) {
539 return !allow_scaling_ && GuestViewBase::PreHandleGestureEvent(source, event); 542 return !allow_scaling_ && GuestViewBase::PreHandleGestureEvent(source, event);
540 } 543 }
541 544
542 void WebViewGuest::LoadProgressChanged(content::WebContents* source, 545 void WebViewGuest::LoadProgressChanged(content::WebContents* source,
543 double progress) { 546 double progress) {
544 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 547 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
545 args->SetString(guestview::kUrl, web_contents()->GetURL().spec()); 548 args->SetString(guest_view::kUrl, web_contents()->GetURL().spec());
546 args->SetDouble(webview::kProgress, progress); 549 args->SetDouble(webview::kProgress, progress);
547 DispatchEventToView( 550 DispatchEventToView(
548 new GuestViewEvent(webview::kEventLoadProgress, args.Pass())); 551 new GuestViewEvent(webview::kEventLoadProgress, args.Pass()));
549 } 552 }
550 553
551 void WebViewGuest::LoadAbort(bool is_top_level, 554 void WebViewGuest::LoadAbort(bool is_top_level,
552 const GURL& url, 555 const GURL& url,
553 int error_code, 556 int error_code,
554 const std::string& error_type) { 557 const std::string& error_type) {
555 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 558 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
556 args->SetBoolean(guestview::kIsTopLevel, is_top_level); 559 args->SetBoolean(guest_view::kIsTopLevel, is_top_level);
557 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); 560 args->SetString(guest_view::kUrl, url.possibly_invalid_spec());
558 args->SetInteger(guestview::kCode, error_code); 561 args->SetInteger(guest_view::kCode, error_code);
559 args->SetString(guestview::kReason, error_type); 562 args->SetString(guest_view::kReason, error_type);
560 DispatchEventToView( 563 DispatchEventToView(
561 new GuestViewEvent(webview::kEventLoadAbort, args.Pass())); 564 new GuestViewEvent(webview::kEventLoadAbort, args.Pass()));
562 } 565 }
563 566
564 void WebViewGuest::CreateNewGuestWebViewWindow( 567 void WebViewGuest::CreateNewGuestWebViewWindow(
565 const content::OpenURLParams& params) { 568 const content::OpenURLParams& params) {
566 GuestViewManager* guest_manager = 569 GuestViewManager* guest_manager =
567 GuestViewManager::FromBrowserContext(browser_context()); 570 GuestViewManager::FromBrowserContext(browser_context());
568 // Set the attach params to use the same partition as the opener. 571 // Set the attach params to use the same partition as the opener.
569 // We pull the partition information from the site's URL, which is of the 572 // We pull the partition information from the site's URL, which is of the
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 ui::PageTransition transition_type) { 761 ui::PageTransition transition_type) {
759 if (!render_frame_host->GetParent()) { 762 if (!render_frame_host->GetParent()) {
760 src_ = url; 763 src_ = url;
761 // Handle a pending zoom if one exists. 764 // Handle a pending zoom if one exists.
762 if (pending_zoom_factor_) { 765 if (pending_zoom_factor_) {
763 SetZoom(pending_zoom_factor_); 766 SetZoom(pending_zoom_factor_);
764 pending_zoom_factor_ = 0.0; 767 pending_zoom_factor_ = 0.0;
765 } 768 }
766 } 769 }
767 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 770 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
768 args->SetString(guestview::kUrl, url.spec()); 771 args->SetString(guest_view::kUrl, url.spec());
769 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); 772 args->SetBoolean(guest_view::kIsTopLevel, !render_frame_host->GetParent());
770 args->SetString(webview::kInternalBaseURLForDataURL, 773 args->SetString(webview::kInternalBaseURLForDataURL,
771 web_contents() 774 web_contents()
772 ->GetController() 775 ->GetController()
773 .GetLastCommittedEntry() 776 .GetLastCommittedEntry()
774 ->GetBaseURLForDataURL() 777 ->GetBaseURLForDataURL()
775 .spec()); 778 .spec());
776 args->SetInteger(webview::kInternalCurrentEntryIndex, 779 args->SetInteger(webview::kInternalCurrentEntryIndex,
777 web_contents()->GetController().GetCurrentEntryIndex()); 780 web_contents()->GetController().GetCurrentEntryIndex());
778 args->SetInteger(webview::kInternalEntryCount, 781 args->SetInteger(webview::kInternalEntryCount,
779 web_contents()->GetController().GetEntryCount()); 782 web_contents()->GetController().GetEntryCount());
(...skipping 18 matching lines...) Expand all
798 LoadAbort(!render_frame_host->GetParent(), validated_url, error_code, 801 LoadAbort(!render_frame_host->GetParent(), validated_url, error_code,
799 net::ErrorToShortString(error_code)); 802 net::ErrorToShortString(error_code));
800 } 803 }
801 804
802 void WebViewGuest::DidStartProvisionalLoadForFrame( 805 void WebViewGuest::DidStartProvisionalLoadForFrame(
803 content::RenderFrameHost* render_frame_host, 806 content::RenderFrameHost* render_frame_host,
804 const GURL& validated_url, 807 const GURL& validated_url,
805 bool is_error_page, 808 bool is_error_page,
806 bool is_iframe_srcdoc) { 809 bool is_iframe_srcdoc) {
807 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 810 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
808 args->SetString(guestview::kUrl, validated_url.spec()); 811 args->SetString(guest_view::kUrl, validated_url.spec());
809 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); 812 args->SetBoolean(guest_view::kIsTopLevel, !render_frame_host->GetParent());
810 DispatchEventToView( 813 DispatchEventToView(
811 new GuestViewEvent(webview::kEventLoadStart, args.Pass())); 814 new GuestViewEvent(webview::kEventLoadStart, args.Pass()));
812 } 815 }
813 816
814 void WebViewGuest::DocumentLoadedInFrame( 817 void WebViewGuest::DocumentLoadedInFrame(
815 content::RenderFrameHost* render_frame_host) { 818 content::RenderFrameHost* render_frame_host) {
816 if (web_view_guest_delegate_) 819 if (web_view_guest_delegate_)
817 web_view_guest_delegate_->OnDocumentLoadedInFrame(render_frame_host); 820 web_view_guest_delegate_->OnDocumentLoadedInFrame(render_frame_host);
818 } 821 }
819 822
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 void WebViewGuest::LoadHandlerCalled() { 863 void WebViewGuest::LoadHandlerCalled() {
861 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 864 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
862 DispatchEventToView( 865 DispatchEventToView(
863 new GuestViewEvent(webview::kEventContentLoad, args.Pass())); 866 new GuestViewEvent(webview::kEventContentLoad, args.Pass()));
864 } 867 }
865 868
866 void WebViewGuest::LoadRedirect(const GURL& old_url, 869 void WebViewGuest::LoadRedirect(const GURL& old_url,
867 const GURL& new_url, 870 const GURL& new_url,
868 bool is_top_level) { 871 bool is_top_level) {
869 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 872 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
870 args->SetBoolean(guestview::kIsTopLevel, is_top_level); 873 args->SetBoolean(guest_view::kIsTopLevel, is_top_level);
871 args->SetString(webview::kNewURL, new_url.spec()); 874 args->SetString(webview::kNewURL, new_url.spec());
872 args->SetString(webview::kOldURL, old_url.spec()); 875 args->SetString(webview::kOldURL, old_url.spec());
873 DispatchEventToView( 876 DispatchEventToView(
874 new GuestViewEvent(webview::kEventLoadRedirect, args.Pass())); 877 new GuestViewEvent(webview::kEventLoadRedirect, args.Pass()));
875 } 878 }
876 879
877 void WebViewGuest::PushWebViewStateToIOThread() { 880 void WebViewGuest::PushWebViewStateToIOThread() {
878 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); 881 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL();
879 std::string partition_domain; 882 std::string partition_domain;
880 std::string partition_id; 883 std::string partition_id;
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 1438 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1436 DispatchEventToView( 1439 DispatchEventToView(
1437 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); 1440 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass()));
1438 } 1441 }
1439 // Since we changed fullscreen state, sending a Resize message ensures that 1442 // Since we changed fullscreen state, sending a Resize message ensures that
1440 // renderer/ sees the change. 1443 // renderer/ sees the change.
1441 web_contents()->GetRenderViewHost()->WasResized(); 1444 web_contents()->GetRenderViewHost()->WasResized();
1442 } 1445 }
1443 1446
1444 } // namespace extensions 1447 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698