OLD | NEW |
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 "chrome/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 "chrome/browser/extensions/api/web_request/web_request_api.h" |
10 #include "chrome/browser/extensions/api/web_view/web_view_internal_api.h" | 11 #include "chrome/browser/extensions/api/web_view/web_view_internal_api.h" |
11 #include "content/public/browser/browser_context.h" | 12 #include "chrome/browser/guest_view/web_view/chrome_web_view_guest_delegate.h" |
| 13 #include "chrome/browser/guest_view/web_view/web_view_constants.h" |
| 14 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" |
| 15 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
| 16 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" |
12 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/child_process_security_policy.h" | 18 #include "content/public/browser/child_process_security_policy.h" |
14 #include "content/public/browser/native_web_keyboard_event.h" | 19 #include "content/public/browser/native_web_keyboard_event.h" |
15 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
16 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
19 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
20 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
21 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/resource_request_details.h" | 27 #include "content/public/browser/resource_request_details.h" |
23 #include "content/public/browser/site_instance.h" | 28 #include "content/public/browser/site_instance.h" |
24 #include "content/public/browser/storage_partition.h" | 29 #include "content/public/browser/storage_partition.h" |
25 #include "content/public/browser/user_metrics.h" | 30 #include "content/public/browser/user_metrics.h" |
26 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
27 #include "content/public/browser/web_contents_delegate.h" | 32 #include "content/public/browser/web_contents_delegate.h" |
28 #include "content/public/common/media_stream_request.h" | 33 #include "content/public/common/media_stream_request.h" |
29 #include "content/public/common/page_zoom.h" | 34 #include "content/public/common/page_zoom.h" |
30 #include "content/public/common/result_codes.h" | 35 #include "content/public/common/result_codes.h" |
31 #include "content/public/common/stop_find_action.h" | 36 #include "content/public/common/stop_find_action.h" |
32 #include "content/public/common/url_constants.h" | 37 #include "content/public/common/url_constants.h" |
33 #include "extensions/browser/api/extensions_api_client.h" | |
34 #include "extensions/browser/extension_system.h" | 38 #include "extensions/browser/extension_system.h" |
35 #include "extensions/browser/guest_view/guest_view_constants.h" | 39 #include "extensions/browser/guest_view/guest_view_constants.h" |
36 #include "extensions/browser/guest_view/guest_view_manager.h" | 40 #include "extensions/browser/guest_view/guest_view_manager.h" |
37 #include "extensions/browser/guest_view/web_view/web_view_constants.h" | |
38 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" | |
39 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" | |
40 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | |
41 #include "extensions/common/constants.h" | 41 #include "extensions/common/constants.h" |
42 #include "extensions/common/extension_messages.h" | 42 #include "extensions/common/extension_messages.h" |
43 #include "ipc/ipc_message_macros.h" | 43 #include "ipc/ipc_message_macros.h" |
44 #include "net/base/escape.h" | 44 #include "net/base/escape.h" |
45 #include "net/base/net_errors.h" | 45 #include "net/base/net_errors.h" |
| 46 #include "third_party/WebKit/public/web/WebFindOptions.h" |
46 #include "ui/base/models/simple_menu_model.h" | 47 #include "ui/base/models/simple_menu_model.h" |
47 | 48 |
48 using base::UserMetricsAction; | 49 using base::UserMetricsAction; |
49 using content::RenderFrameHost; | 50 using content::RenderFrameHost; |
50 using content::ResourceType; | 51 using content::ResourceType; |
51 using content::WebContents; | 52 using content::WebContents; |
52 | 53 |
53 namespace extensions { | 54 namespace extensions { |
54 | 55 |
55 namespace { | 56 namespace { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 NOTREACHED() << "Unknown Termination Status."; | 95 NOTREACHED() << "Unknown Termination Status."; |
95 return "unknown"; | 96 return "unknown"; |
96 } | 97 } |
97 | 98 |
98 std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) { | 99 std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) { |
99 const std::string& partition_id = site_url.query(); | 100 const std::string& partition_id = site_url.query(); |
100 bool persist_storage = site_url.path().find("persist") != std::string::npos; | 101 bool persist_storage = site_url.path().find("persist") != std::string::npos; |
101 return (persist_storage ? webview::kPersistPrefix : "") + partition_id; | 102 return (persist_storage ? webview::kPersistPrefix : "") + partition_id; |
102 } | 103 } |
103 | 104 |
| 105 void RemoveWebViewEventListenersOnIOThread( |
| 106 void* profile, |
| 107 const std::string& extension_id, |
| 108 int embedder_process_id, |
| 109 int view_instance_id) { |
| 110 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 111 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( |
| 112 profile, |
| 113 extension_id, |
| 114 embedder_process_id, |
| 115 view_instance_id); |
| 116 } |
| 117 |
104 void ParsePartitionParam(const base::DictionaryValue& create_params, | 118 void ParsePartitionParam(const base::DictionaryValue& create_params, |
105 std::string* storage_partition_id, | 119 std::string* storage_partition_id, |
106 bool* persist_storage) { | 120 bool* persist_storage) { |
107 std::string partition_str; | 121 std::string partition_str; |
108 if (!create_params.GetString(webview::kStoragePartitionId, &partition_str)) { | 122 if (!create_params.GetString(webview::kStoragePartitionId, &partition_str)) { |
109 return; | 123 return; |
110 } | 124 } |
111 | 125 |
112 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on | 126 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on |
113 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely | 127 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); | 318 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); |
305 } | 319 } |
306 | 320 |
307 void WebViewGuest::DidStopLoading() { | 321 void WebViewGuest::DidStopLoading() { |
308 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 322 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
309 DispatchEventToEmbedder( | 323 DispatchEventToEmbedder( |
310 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); | 324 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); |
311 } | 325 } |
312 | 326 |
313 void WebViewGuest::EmbedderDestroyed() { | 327 void WebViewGuest::EmbedderDestroyed() { |
314 if (web_view_guest_delegate_) | 328 // TODO(fsamuel): WebRequest event listeners for <webview> should survive |
315 web_view_guest_delegate_->OnEmbedderDestroyed(); | 329 // reparenting of a <webview> within a single embedder. Right now, we keep |
| 330 // around the browser state for the listener for the lifetime of the embedder. |
| 331 // Ideally, the lifetime of the listeners should match the lifetime of the |
| 332 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move |
| 333 // the call to RemoveWebViewEventListenersOnIOThread back to |
| 334 // WebViewGuest::WebContentsDestroyed. |
| 335 content::BrowserThread::PostTask( |
| 336 content::BrowserThread::IO, |
| 337 FROM_HERE, |
| 338 base::Bind( |
| 339 &RemoveWebViewEventListenersOnIOThread, |
| 340 browser_context(), embedder_extension_id(), |
| 341 embedder_render_process_id(), |
| 342 view_instance_id())); |
316 } | 343 } |
317 | 344 |
318 void WebViewGuest::GuestDestroyed() { | 345 void WebViewGuest::GuestDestroyed() { |
319 // Clean up custom context menu items for this guest. | 346 // Clean up custom context menu items for this guest. |
320 if (web_view_guest_delegate_) | 347 if (web_view_guest_delegate_) |
321 web_view_guest_delegate_->OnGuestDestroyed(); | 348 web_view_guest_delegate_->OnGuestDestroyed(); |
322 RemoveWebViewStateFromIOThread(web_contents()); | 349 RemoveWebViewStateFromIOThread(web_contents()); |
323 } | 350 } |
324 | 351 |
325 void WebViewGuest::GuestReady() { | 352 void WebViewGuest::GuestReady() { |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 callback); | 629 callback); |
603 return true; | 630 return true; |
604 } | 631 } |
605 | 632 |
606 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, | 633 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, |
607 int guest_instance_id) | 634 int guest_instance_id) |
608 : GuestView<WebViewGuest>(browser_context, guest_instance_id), | 635 : GuestView<WebViewGuest>(browser_context, guest_instance_id), |
609 is_overriding_user_agent_(false), | 636 is_overriding_user_agent_(false), |
610 find_helper_(this), | 637 find_helper_(this), |
611 javascript_dialog_helper_(this) { | 638 javascript_dialog_helper_(this) { |
612 web_view_guest_delegate_.reset( | 639 web_view_guest_delegate_.reset(new ChromeWebViewGuestDelegate(this)); |
613 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); | |
614 } | 640 } |
615 | 641 |
616 WebViewGuest::~WebViewGuest() { | 642 WebViewGuest::~WebViewGuest() { |
617 } | 643 } |
618 | 644 |
619 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 645 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
620 content::RenderFrameHost* render_frame_host, | 646 content::RenderFrameHost* render_frame_host, |
621 const GURL& url, | 647 const GURL& url, |
622 content::PageTransition transition_type) { | 648 content::PageTransition transition_type) { |
623 find_helper_.CancelAllFindSessions(); | 649 find_helper_.CancelAllFindSessions(); |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 WebViewGuest* guest = | 1122 WebViewGuest* guest = |
1097 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1123 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1098 if (!guest) | 1124 if (!guest) |
1099 return; | 1125 return; |
1100 | 1126 |
1101 if (!allow) | 1127 if (!allow) |
1102 guest->Destroy(); | 1128 guest->Destroy(); |
1103 } | 1129 } |
1104 | 1130 |
1105 } // namespace extensions | 1131 } // namespace extensions |
OLD | NEW |