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 | 5 |
6 #include "chrome/browser/guest_view/web_view/chrome_web_view_guest_delegate.h" | 6 #include "chrome/browser/guest_view/web_view/chrome_web_view_guest_delegate.h" |
7 | 7 |
8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
9 #include "chrome/browser/favicon/favicon_tab_helper.h" | 9 #include "chrome/browser/favicon/favicon_tab_helper.h" |
10 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 10 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
11 #include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h" | 11 #include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h" |
12 #include "chrome/browser/ui/zoom/zoom_controller.h" | 12 #include "chrome/browser/ui/zoom/zoom_controller.h" |
13 #include "chrome/common/chrome_version_info.h" | 13 #include "chrome/common/chrome_version_info.h" |
14 #include "components/pdf/browser/pdf_web_contents_helper.h" | 14 #include "components/pdf/browser/pdf_web_contents_helper.h" |
15 #include "components/renderer_context_menu/context_menu_delegate.h" | 15 #include "components/renderer_context_menu/context_menu_delegate.h" |
16 #include "content/public/common/page_zoom.h" | 16 #include "content/public/common/page_zoom.h" |
17 #include "extensions/browser/api/web_request/web_request_api.h" | 17 #include "extensions/browser/api/web_request/web_request_api.h" |
18 #include "extensions/browser/guest_view/web_view/web_view_constants.h" | 18 #include "extensions/browser/guest_view/web_view/web_view_constants.h" |
19 | 19 |
20 #if defined(ENABLE_PRINTING) | 20 #if defined(ENABLE_PRINTING) |
21 #if defined(ENABLE_FULL_PRINTING) | 21 #if defined(ENABLE_FULL_PRINTING) |
22 #include "chrome/browser/printing/print_preview_message_handler.h" | 22 #include "chrome/browser/printing/print_preview_message_handler.h" |
23 #include "chrome/browser/printing/print_view_manager.h" | 23 #include "chrome/browser/printing/print_view_manager.h" |
24 #else | 24 #else |
25 #include "chrome/browser/printing/print_view_manager_basic.h" | 25 #include "chrome/browser/printing/print_view_manager_basic.h" |
26 #endif // defined(ENABLE_FULL_PRINTING) | 26 #endif // defined(ENABLE_FULL_PRINTING) |
27 #endif // defined(ENABLE_PRINTING) | 27 #endif // defined(ENABLE_PRINTING) |
28 | 28 |
| 29 void RemoveWebViewEventListenersOnIOThread( |
| 30 void* profile, |
| 31 const std::string& extension_id, |
| 32 int embedder_process_id, |
| 33 int view_instance_id) { |
| 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 35 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( |
| 36 profile, |
| 37 extension_id, |
| 38 embedder_process_id, |
| 39 view_instance_id); |
| 40 } |
| 41 |
29 ChromeWebViewGuestDelegate::ChromeWebViewGuestDelegate( | 42 ChromeWebViewGuestDelegate::ChromeWebViewGuestDelegate( |
30 extensions::WebViewGuest* web_view_guest) | 43 extensions::WebViewGuest* web_view_guest) |
31 : pending_context_menu_request_id_(0), | 44 : pending_context_menu_request_id_(0), |
32 chromevox_injected_(false), | 45 chromevox_injected_(false), |
33 current_zoom_factor_(1.0), | 46 current_zoom_factor_(1.0), |
34 web_view_guest_(web_view_guest) { | 47 web_view_guest_(web_view_guest) { |
35 } | 48 } |
36 | 49 |
37 ChromeWebViewGuestDelegate::~ChromeWebViewGuestDelegate() { | 50 ChromeWebViewGuestDelegate::~ChromeWebViewGuestDelegate() { |
38 } | 51 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 #else | 97 #else |
85 printing::PrintViewManagerBasic::CreateForWebContents(contents); | 98 printing::PrintViewManagerBasic::CreateForWebContents(contents); |
86 #endif // defined(ENABLE_FULL_PRINTING) | 99 #endif // defined(ENABLE_FULL_PRINTING) |
87 #endif // defined(ENABLE_PRINTING) | 100 #endif // defined(ENABLE_PRINTING) |
88 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient( | 101 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient( |
89 contents, | 102 contents, |
90 scoped_ptr<pdf::PDFWebContentsHelperClient>( | 103 scoped_ptr<pdf::PDFWebContentsHelperClient>( |
91 new ChromePDFWebContentsHelperClient())); | 104 new ChromePDFWebContentsHelperClient())); |
92 } | 105 } |
93 | 106 |
| 107 void ChromeWebViewGuestDelegate::OnEmbedderDestroyed() { |
| 108 // TODO(fsamuel): WebRequest event listeners for <webview> should survive |
| 109 // reparenting of a <webview> within a single embedder. Right now, we keep |
| 110 // around the browser state for the listener for the lifetime of the embedder. |
| 111 // Ideally, the lifetime of the listeners should match the lifetime of the |
| 112 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move |
| 113 // the call to RemoveWebViewEventListenersOnIOThread back to |
| 114 // WebViewGuest::WebContentsDestroyed. |
| 115 content::BrowserThread::PostTask( |
| 116 content::BrowserThread::IO, |
| 117 FROM_HERE, |
| 118 base::Bind( |
| 119 &RemoveWebViewEventListenersOnIOThread, |
| 120 web_view_guest()->browser_context(), |
| 121 web_view_guest()->embedder_extension_id(), |
| 122 web_view_guest()->embedder_render_process_id(), |
| 123 web_view_guest()->view_instance_id())); |
| 124 } |
| 125 |
94 void ChromeWebViewGuestDelegate::OnDidAttachToEmbedder() { | 126 void ChromeWebViewGuestDelegate::OnDidAttachToEmbedder() { |
95 // TODO(fsamuel): This code should be implemented in GuestViewBase once the | 127 // TODO(fsamuel): This code should be implemented in GuestViewBase once the |
96 // ZoomController moves to the extensions module. | 128 // ZoomController moves to the extensions module. |
97 ZoomController* zoom_controller = ZoomController::FromWebContents( | 129 ZoomController* zoom_controller = ZoomController::FromWebContents( |
98 web_view_guest()->embedder_web_contents()); | 130 web_view_guest()->embedder_web_contents()); |
99 if (!zoom_controller) | 131 if (!zoom_controller) |
100 return; | 132 return; |
101 // Listen to the embedder's zoom changes. | 133 // Listen to the embedder's zoom changes. |
102 zoom_controller->AddObserver(this); | 134 zoom_controller->AddObserver(this); |
103 // Set the guest's initial zoom level to be equal to the embedder's. | 135 // Set the guest's initial zoom level to be equal to the embedder's. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 chromevox_injected_ = false; | 251 chromevox_injected_ = false; |
220 } | 252 } |
221 } | 253 } |
222 #endif | 254 #endif |
223 | 255 |
224 void ChromeWebViewGuestDelegate::OnZoomChanged( | 256 void ChromeWebViewGuestDelegate::OnZoomChanged( |
225 const ZoomController::ZoomChangedEventData& data) { | 257 const ZoomController::ZoomChangedEventData& data) { |
226 ZoomController::FromWebContents(guest_web_contents())-> | 258 ZoomController::FromWebContents(guest_web_contents())-> |
227 SetZoomLevel(data.new_zoom_level); | 259 SetZoomLevel(data.new_zoom_level); |
228 } | 260 } |
OLD | NEW |