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

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: Remove dependency of web_view_internal_api.h Created 6 years, 3 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" 10 #include "content/public/browser/browser_context.h"
11 #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"
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" 11 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/child_process_security_policy.h" 12 #include "content/public/browser/child_process_security_policy.h"
19 #include "content/public/browser/native_web_keyboard_event.h" 13 #include "content/public/browser/native_web_keyboard_event.h"
20 #include "content/public/browser/navigation_entry.h" 14 #include "content/public/browser/navigation_entry.h"
21 #include "content/public/browser/notification_details.h" 15 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/notification_source.h" 17 #include "content/public/browser/notification_source.h"
24 #include "content/public/browser/notification_types.h" 18 #include "content/public/browser/notification_types.h"
25 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/render_view_host.h" 20 #include "content/public/browser/render_view_host.h"
27 #include "content/public/browser/resource_request_details.h" 21 #include "content/public/browser/resource_request_details.h"
28 #include "content/public/browser/site_instance.h" 22 #include "content/public/browser/site_instance.h"
29 #include "content/public/browser/storage_partition.h" 23 #include "content/public/browser/storage_partition.h"
30 #include "content/public/browser/user_metrics.h" 24 #include "content/public/browser/user_metrics.h"
31 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
32 #include "content/public/browser/web_contents_delegate.h" 26 #include "content/public/browser/web_contents_delegate.h"
33 #include "content/public/common/media_stream_request.h" 27 #include "content/public/common/media_stream_request.h"
34 #include "content/public/common/page_zoom.h" 28 #include "content/public/common/page_zoom.h"
35 #include "content/public/common/result_codes.h" 29 #include "content/public/common/result_codes.h"
36 #include "content/public/common/stop_find_action.h" 30 #include "content/public/common/stop_find_action.h"
37 #include "content/public/common/url_constants.h" 31 #include "content/public/common/url_constants.h"
32 #include "extensions/browser/api/extensions_api_client.h"
38 #include "extensions/browser/extension_system.h" 33 #include "extensions/browser/extension_system.h"
39 #include "extensions/browser/guest_view/guest_view_constants.h" 34 #include "extensions/browser/guest_view/guest_view_constants.h"
40 #include "extensions/browser/guest_view/guest_view_manager.h" 35 #include "extensions/browser/guest_view/guest_view_manager.h"
36 #include "extensions/browser/guest_view/web_view/web_view_constants.h"
37 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
38 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h"
39 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
41 #include "extensions/common/constants.h" 40 #include "extensions/common/constants.h"
42 #include "extensions/common/extension_messages.h" 41 #include "extensions/common/extension_messages.h"
43 #include "ipc/ipc_message_macros.h" 42 #include "ipc/ipc_message_macros.h"
44 #include "net/base/escape.h" 43 #include "net/base/escape.h"
45 #include "net/base/net_errors.h" 44 #include "net/base/net_errors.h"
46 #include "third_party/WebKit/public/web/WebFindOptions.h"
47 #include "ui/base/models/simple_menu_model.h" 45 #include "ui/base/models/simple_menu_model.h"
48 46
49 using base::UserMetricsAction; 47 using base::UserMetricsAction;
50 using content::RenderFrameHost; 48 using content::RenderFrameHost;
51 using content::ResourceType; 49 using content::ResourceType;
52 using content::WebContents; 50 using content::WebContents;
53 51
54 namespace extensions { 52 namespace extensions {
55 53
56 namespace { 54 namespace {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 NOTREACHED() << "Unknown Termination Status."; 93 NOTREACHED() << "Unknown Termination Status.";
96 return "unknown"; 94 return "unknown";
97 } 95 }
98 96
99 std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) { 97 std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) {
100 const std::string& partition_id = site_url.query(); 98 const std::string& partition_id = site_url.query();
101 bool persist_storage = site_url.path().find("persist") != std::string::npos; 99 bool persist_storage = site_url.path().find("persist") != std::string::npos;
102 return (persist_storage ? webview::kPersistPrefix : "") + partition_id; 100 return (persist_storage ? webview::kPersistPrefix : "") + partition_id;
103 } 101 }
104 102
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, 103 void ParsePartitionParam(const base::DictionaryValue& create_params,
119 std::string* storage_partition_id, 104 std::string* storage_partition_id,
120 bool* persist_storage) { 105 bool* persist_storage) {
121 std::string partition_str; 106 std::string partition_str;
122 if (!create_params.GetString(webview::kStoragePartitionId, &partition_str)) { 107 if (!create_params.GetString(webview::kStoragePartitionId, &partition_str)) {
123 return; 108 return;
124 } 109 }
125 110
126 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on 111 // 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 112 // 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)); 303 web_view_permission_helper_.reset(new WebViewPermissionHelper(this));
319 } 304 }
320 305
321 void WebViewGuest::DidStopLoading() { 306 void WebViewGuest::DidStopLoading() {
322 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 307 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
323 DispatchEventToEmbedder( 308 DispatchEventToEmbedder(
324 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); 309 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass()));
325 } 310 }
326 311
327 void WebViewGuest::EmbedderDestroyed() { 312 void WebViewGuest::EmbedderDestroyed() {
328 // TODO(fsamuel): WebRequest event listeners for <webview> should survive 313 if (web_view_guest_delegate_)
329 // reparenting of a <webview> within a single embedder. Right now, we keep 314 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 } 315 }
344 316
345 void WebViewGuest::GuestDestroyed() { 317 void WebViewGuest::GuestDestroyed() {
346 // Clean up custom context menu items for this guest. 318 // Clean up custom context menu items for this guest.
347 if (web_view_guest_delegate_) 319 if (web_view_guest_delegate_)
348 web_view_guest_delegate_->OnGuestDestroyed(); 320 web_view_guest_delegate_->OnGuestDestroyed();
349 RemoveWebViewStateFromIOThread(web_contents()); 321 RemoveWebViewStateFromIOThread(web_contents());
350 } 322 }
351 323
352 void WebViewGuest::GuestReady() { 324 void WebViewGuest::GuestReady() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 DispatchEventToEmbedder( 374 DispatchEventToEmbedder(
403 new GuestViewBase::Event(webview::kEventClose, args.Pass())); 375 new GuestViewBase::Event(webview::kEventClose, args.Pass()));
404 } 376 }
405 377
406 void WebViewGuest::FindReply(WebContents* source, 378 void WebViewGuest::FindReply(WebContents* source,
407 int request_id, 379 int request_id,
408 int number_of_matches, 380 int number_of_matches,
409 const gfx::Rect& selection_rect, 381 const gfx::Rect& selection_rect,
410 int active_match_ordinal, 382 int active_match_ordinal,
411 bool final_update) { 383 bool final_update) {
412 find_helper_.FindReply(request_id, number_of_matches, selection_rect, 384 if (web_view_guest_delegate_) {
413 active_match_ordinal, final_update); 385 web_view_guest_delegate_->FindReply(
386 source, request_id, number_of_matches,
387 selection_rect, active_match_ordinal, final_update);
388 }
414 } 389 }
415 390
416 bool WebViewGuest::HandleContextMenu( 391 bool WebViewGuest::HandleContextMenu(
417 const content::ContextMenuParams& params) { 392 const content::ContextMenuParams& params) {
418 if (!web_view_guest_delegate_) 393 if (!web_view_guest_delegate_)
419 return false; 394 return false;
420 return web_view_guest_delegate_->HandleContextMenu(params); 395 return web_view_guest_delegate_->HandleContextMenu(params);
421 } 396 }
422 397
423 void WebViewGuest::HandleKeyboardEvent( 398 void WebViewGuest::HandleKeyboardEvent(
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 532
558 double WebViewGuest::GetZoom() { 533 double WebViewGuest::GetZoom() {
559 if (!web_view_guest_delegate_) 534 if (!web_view_guest_delegate_)
560 return 1.0; 535 return 1.0;
561 return web_view_guest_delegate_->GetZoom(); 536 return web_view_guest_delegate_->GetZoom();
562 } 537 }
563 538
564 void WebViewGuest::Find( 539 void WebViewGuest::Find(
565 const base::string16& search_text, 540 const base::string16& search_text,
566 const blink::WebFindOptions& options, 541 const blink::WebFindOptions& options,
567 scoped_refptr<WebViewInternalFindFunction> find_function) { 542 WebViewInternalFindFunction* find_function) {
568 find_helper_.Find(guest_web_contents(), search_text, options, find_function); 543 if (web_view_guest_delegate_)
544 web_view_guest_delegate_->Find(search_text, options, find_function);
569 } 545 }
570 546
571 void WebViewGuest::StopFinding(content::StopFindAction action) { 547 void WebViewGuest::StopFinding(content::StopFindAction action) {
572 find_helper_.CancelAllFindSessions(); 548 if (web_view_guest_delegate_)
573 guest_web_contents()->StopFinding(action); 549 web_view_guest_delegate_->StopFinding(action);
574 } 550 }
575 551
576 void WebViewGuest::Go(int relative_index) { 552 void WebViewGuest::Go(int relative_index) {
577 guest_web_contents()->GetController().GoToOffset(relative_index); 553 guest_web_contents()->GetController().GoToOffset(relative_index);
578 } 554 }
579 555
580 void WebViewGuest::Reload() { 556 void WebViewGuest::Reload() {
581 // TODO(fsamuel): Don't check for repost because we don't want to show 557 // TODO(fsamuel): Don't check for repost because we don't want to show
582 // Chromium's repost warning. We might want to implement a separate API 558 // Chromium's repost warning. We might want to implement a separate API
583 // for registering a callback if a repost is about to happen. 559 // for registering a callback if a repost is about to happen.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 remove_since, 603 remove_since,
628 base::Time::Now(), 604 base::Time::Now(),
629 callback); 605 callback);
630 return true; 606 return true;
631 } 607 }
632 608
633 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, 609 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context,
634 int guest_instance_id) 610 int guest_instance_id)
635 : GuestView<WebViewGuest>(browser_context, guest_instance_id), 611 : GuestView<WebViewGuest>(browser_context, guest_instance_id),
636 is_overriding_user_agent_(false), 612 is_overriding_user_agent_(false),
637 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();
650
651 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 625 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
652 args->SetString(guestview::kUrl, url.spec()); 626 args->SetString(guestview::kUrl, url.spec());
653 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); 627 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent());
654 args->SetInteger(webview::kInternalCurrentEntryIndex, 628 args->SetInteger(webview::kInternalCurrentEntryIndex,
655 guest_web_contents()->GetController().GetCurrentEntryIndex()); 629 guest_web_contents()->GetController().GetCurrentEntryIndex());
656 args->SetInteger(webview::kInternalEntryCount, 630 args->SetInteger(webview::kInternalEntryCount,
657 guest_web_contents()->GetController().GetEntryCount()); 631 guest_web_contents()->GetController().GetEntryCount());
658 args->SetInteger(webview::kInternalProcessId, 632 args->SetInteger(webview::kInternalProcessId,
659 guest_web_contents()->GetRenderProcessHost()->GetID()); 633 guest_web_contents()->GetRenderProcessHost()->GetID());
660 DispatchEventToEmbedder( 634 DispatchEventToEmbedder(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 RenderFrameHost* render_frame_host) { 670 RenderFrameHost* render_frame_host) {
697 bool handled = true; 671 bool handled = true;
698 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) 672 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message)
699 IPC_MESSAGE_HANDLER(ExtensionHostMsg_FrameNameChanged, OnFrameNameChanged) 673 IPC_MESSAGE_HANDLER(ExtensionHostMsg_FrameNameChanged, OnFrameNameChanged)
700 IPC_MESSAGE_UNHANDLED(handled = false) 674 IPC_MESSAGE_UNHANDLED(handled = false)
701 IPC_END_MESSAGE_MAP() 675 IPC_END_MESSAGE_MAP()
702 return handled; 676 return handled;
703 } 677 }
704 678
705 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { 679 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) {
706 // Cancel all find sessions in progress. 680 if (web_view_guest_delegate_)
707 find_helper_.CancelAllFindSessions(); 681 web_view_guest_delegate_->OnRenderProcessGone();
708 682
709 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 683 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
710 args->SetInteger(webview::kProcessId, 684 args->SetInteger(webview::kProcessId,
711 guest_web_contents()->GetRenderProcessHost()->GetID()); 685 guest_web_contents()->GetRenderProcessHost()->GetID());
712 args->SetString(webview::kReason, TerminationStatusToString(status)); 686 args->SetString(webview::kReason, TerminationStatusToString(status));
713 DispatchEventToEmbedder( 687 DispatchEventToEmbedder(
714 new GuestViewBase::Event(webview::kEventExit, args.Pass())); 688 new GuestViewBase::Event(webview::kEventExit, args.Pass()));
715 } 689 }
716 690
717 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { 691 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) {
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698