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