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 | |
42 ChromeWebViewGuestDelegate::ChromeWebViewGuestDelegate( | 29 ChromeWebViewGuestDelegate::ChromeWebViewGuestDelegate( |
43 extensions::WebViewGuest* web_view_guest) | 30 extensions::WebViewGuest* web_view_guest) |
44 : pending_context_menu_request_id_(0), | 31 : pending_context_menu_request_id_(0), |
45 chromevox_injected_(false), | 32 chromevox_injected_(false), |
46 current_zoom_factor_(1.0), | 33 current_zoom_factor_(1.0), |
47 web_view_guest_(web_view_guest) { | 34 web_view_guest_(web_view_guest) { |
48 } | 35 } |
49 | 36 |
50 ChromeWebViewGuestDelegate::~ChromeWebViewGuestDelegate() { | 37 ChromeWebViewGuestDelegate::~ChromeWebViewGuestDelegate() { |
51 } | 38 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 #else | 84 #else |
98 printing::PrintViewManagerBasic::CreateForWebContents(contents); | 85 printing::PrintViewManagerBasic::CreateForWebContents(contents); |
99 #endif // defined(ENABLE_FULL_PRINTING) | 86 #endif // defined(ENABLE_FULL_PRINTING) |
100 #endif // defined(ENABLE_PRINTING) | 87 #endif // defined(ENABLE_PRINTING) |
101 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient( | 88 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient( |
102 contents, | 89 contents, |
103 scoped_ptr<pdf::PDFWebContentsHelperClient>( | 90 scoped_ptr<pdf::PDFWebContentsHelperClient>( |
104 new ChromePDFWebContentsHelperClient())); | 91 new ChromePDFWebContentsHelperClient())); |
105 } | 92 } |
106 | 93 |
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 | |
126 void ChromeWebViewGuestDelegate::OnDidAttachToEmbedder() { | 94 void ChromeWebViewGuestDelegate::OnDidAttachToEmbedder() { |
127 // TODO(fsamuel): This code should be implemented in GuestViewBase once the | 95 // TODO(fsamuel): This code should be implemented in GuestViewBase once the |
128 // ZoomController moves to the extensions module. | 96 // ZoomController moves to the extensions module. |
129 ZoomController* zoom_controller = ZoomController::FromWebContents( | 97 ZoomController* zoom_controller = ZoomController::FromWebContents( |
130 web_view_guest()->embedder_web_contents()); | 98 web_view_guest()->embedder_web_contents()); |
131 if (!zoom_controller) | 99 if (!zoom_controller) |
132 return; | 100 return; |
133 // Listen to the embedder's zoom changes. | 101 // Listen to the embedder's zoom changes. |
134 zoom_controller->AddObserver(this); | 102 zoom_controller->AddObserver(this); |
135 // Set the guest's initial zoom level to be equal to the embedder's. | 103 // 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... |
251 chromevox_injected_ = false; | 219 chromevox_injected_ = false; |
252 } | 220 } |
253 } | 221 } |
254 #endif | 222 #endif |
255 | 223 |
256 void ChromeWebViewGuestDelegate::OnZoomChanged( | 224 void ChromeWebViewGuestDelegate::OnZoomChanged( |
257 const ZoomController::ZoomChangedEventData& data) { | 225 const ZoomController::ZoomChangedEventData& data) { |
258 ZoomController::FromWebContents(guest_web_contents())-> | 226 ZoomController::FromWebContents(guest_web_contents())-> |
259 SetZoomLevel(data.new_zoom_level); | 227 SetZoomLevel(data.new_zoom_level); |
260 } | 228 } |
OLD | NEW |