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

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

Issue 496873006: Move core web_view code to extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move guest view type registers to extensions && remove dependency of web_request_api.h. Created 6 years, 4 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 "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" 46 #include "third_party/WebKit/public/web/WebFindOptions.h"
47 #include "ui/base/models/simple_menu_model.h" 47 #include "ui/base/models/simple_menu_model.h"
48 48
49 using base::UserMetricsAction; 49 using base::UserMetricsAction;
50 using content::RenderFrameHost; 50 using content::RenderFrameHost;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 NOTREACHED() << "Unknown Termination Status."; 95 NOTREACHED() << "Unknown Termination Status.";
96 return "unknown"; 96 return "unknown";
97 } 97 }
98 98
99 std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) { 99 std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) {
100 const std::string& partition_id = site_url.query(); 100 const std::string& partition_id = site_url.query();
101 bool persist_storage = site_url.path().find("persist") != std::string::npos; 101 bool persist_storage = site_url.path().find("persist") != std::string::npos;
102 return (persist_storage ? webview::kPersistPrefix : "") + partition_id; 102 return (persist_storage ? webview::kPersistPrefix : "") + partition_id;
103 } 103 }
104 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
118 void ParsePartitionParam(const base::DictionaryValue& create_params, 105 void ParsePartitionParam(const base::DictionaryValue& create_params,
119 std::string* storage_partition_id, 106 std::string* storage_partition_id,
120 bool* persist_storage) { 107 bool* persist_storage) {
121 std::string partition_str; 108 std::string partition_str;
122 if (!create_params.GetString(webview::kStoragePartitionId, &partition_str)) { 109 if (!create_params.GetString(webview::kStoragePartitionId, &partition_str)) {
123 return; 110 return;
124 } 111 }
125 112
126 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on 113 // 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 114 // 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
318 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); 305 web_view_permission_helper_.reset(new WebViewPermissionHelper(this));
319 } 306 }
320 307
321 void WebViewGuest::DidStopLoading() { 308 void WebViewGuest::DidStopLoading() {
322 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 309 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
323 DispatchEventToEmbedder( 310 DispatchEventToEmbedder(
324 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); 311 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass()));
325 } 312 }
326 313
327 void WebViewGuest::EmbedderDestroyed() { 314 void WebViewGuest::EmbedderDestroyed() {
328 // TODO(fsamuel): WebRequest event listeners for <webview> should survive 315 if (web_view_guest_delegate_) {
Fady Samuel 2014/08/23 11:00:02 Remove block since it's a single line statement.
329 // reparenting of a <webview> within a single embedder. Right now, we keep 316 web_view_guest_delegate_->OnEmbedderDestroyed();
330 // around the browser state for the listener for the lifetime of the embedder. 317 }
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 } 318 }
344 319
345 void WebViewGuest::GuestDestroyed() { 320 void WebViewGuest::GuestDestroyed() {
346 // Clean up custom context menu items for this guest. 321 // Clean up custom context menu items for this guest.
347 if (web_view_guest_delegate_) 322 if (web_view_guest_delegate_)
348 web_view_guest_delegate_->OnGuestDestroyed(); 323 web_view_guest_delegate_->OnGuestDestroyed();
349 RemoveWebViewStateFromIOThread(web_contents()); 324 RemoveWebViewStateFromIOThread(web_contents());
350 } 325 }
351 326
352 void WebViewGuest::GuestReady() { 327 void WebViewGuest::GuestReady() {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 callback); 604 callback);
630 return true; 605 return true;
631 } 606 }
632 607
633 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, 608 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context,
634 int guest_instance_id) 609 int guest_instance_id)
635 : GuestView<WebViewGuest>(browser_context, guest_instance_id), 610 : GuestView<WebViewGuest>(browser_context, guest_instance_id),
636 is_overriding_user_agent_(false), 611 is_overriding_user_agent_(false),
637 find_helper_(this), 612 find_helper_(this),
638 javascript_dialog_helper_(this) { 613 javascript_dialog_helper_(this) {
639 web_view_guest_delegate_.reset(new ChromeWebViewGuestDelegate(this)); 614 web_view_guest_delegate_.reset(
615 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this));
640 } 616 }
641 617
642 WebViewGuest::~WebViewGuest() { 618 WebViewGuest::~WebViewGuest() {
643 } 619 }
644 620
645 void WebViewGuest::DidCommitProvisionalLoadForFrame( 621 void WebViewGuest::DidCommitProvisionalLoadForFrame(
646 content::RenderFrameHost* render_frame_host, 622 content::RenderFrameHost* render_frame_host,
647 const GURL& url, 623 const GURL& url,
648 content::PageTransition transition_type) { 624 content::PageTransition transition_type) {
649 find_helper_.CancelAllFindSessions(); 625 find_helper_.CancelAllFindSessions();
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 WebViewGuest* guest = 1098 WebViewGuest* guest =
1123 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1099 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1124 if (!guest) 1100 if (!guest)
1125 return; 1101 return;
1126 1102
1127 if (!allow) 1103 if (!allow)
1128 guest->Destroy(); 1104 guest->Destroy();
1129 } 1105 }
1130 1106
1131 } // namespace extensions 1107 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698