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/api/web_request/web_request_api.h" | |
9 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
10 #include "chrome/browser/favicon/favicon_tab_helper.h" | 9 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 10 #include "chrome/browser/guest_view/web_view/web_view_constants.h" |
11 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 11 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
12 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" | 12 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" |
13 #include "chrome/browser/ui/zoom/zoom_controller.h" | 13 #include "chrome/browser/ui/zoom/zoom_controller.h" |
14 #include "chrome/common/chrome_version_info.h" | 14 #include "chrome/common/chrome_version_info.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/guest_view/web_view/web_view_constants.h" | |
18 | 17 |
19 #if defined(ENABLE_PRINTING) | 18 #if defined(ENABLE_PRINTING) |
20 #if defined(ENABLE_FULL_PRINTING) | 19 #if defined(ENABLE_FULL_PRINTING) |
21 #include "chrome/browser/printing/print_preview_message_handler.h" | 20 #include "chrome/browser/printing/print_preview_message_handler.h" |
22 #include "chrome/browser/printing/print_view_manager.h" | 21 #include "chrome/browser/printing/print_view_manager.h" |
23 #else | 22 #else |
24 #include "chrome/browser/printing/print_view_manager_basic.h" | 23 #include "chrome/browser/printing/print_view_manager_basic.h" |
25 #endif // defined(ENABLE_FULL_PRINTING) | 24 #endif // defined(ENABLE_FULL_PRINTING) |
26 #endif // defined(ENABLE_PRINTING) | 25 #endif // defined(ENABLE_PRINTING) |
27 | 26 |
28 void RemoveWebViewEventListenersOnIOThread( | |
29 void* profile, | |
30 const std::string& extension_id, | |
31 int embedder_process_id, | |
32 int view_instance_id) { | |
33 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
34 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( | |
35 profile, | |
36 extension_id, | |
37 embedder_process_id, | |
38 view_instance_id); | |
39 } | |
40 | |
41 ChromeWebViewGuestDelegate::ChromeWebViewGuestDelegate( | 27 ChromeWebViewGuestDelegate::ChromeWebViewGuestDelegate( |
42 extensions::WebViewGuest* web_view_guest) | 28 extensions::WebViewGuest* web_view_guest) |
43 : WebViewGuestDelegate(web_view_guest), | 29 : WebViewGuestDelegate(), |
44 pending_context_menu_request_id_(0), | 30 pending_context_menu_request_id_(0), |
45 chromevox_injected_(false), | 31 chromevox_injected_(false), |
46 current_zoom_factor_(1.0) { | 32 current_zoom_factor_(1.0), |
| 33 web_view_guest_(web_view_guest) { |
47 } | 34 } |
48 | 35 |
49 ChromeWebViewGuestDelegate::~ChromeWebViewGuestDelegate() { | 36 ChromeWebViewGuestDelegate::~ChromeWebViewGuestDelegate() { |
50 } | 37 } |
51 | 38 |
52 double ChromeWebViewGuestDelegate::GetZoom() { | 39 double ChromeWebViewGuestDelegate::GetZoom() { |
53 return current_zoom_factor_; | 40 return current_zoom_factor_; |
54 } | 41 } |
55 | 42 |
56 bool ChromeWebViewGuestDelegate::HandleContextMenu( | 43 bool ChromeWebViewGuestDelegate::HandleContextMenu( |
57 const content::ContextMenuParams& params) { | 44 const content::ContextMenuParams& params) { |
58 ContextMenuDelegate* menu_delegate = | 45 ContextMenuDelegate* menu_delegate = |
59 ContextMenuDelegate::FromWebContents(guest_web_contents()); | 46 ContextMenuDelegate::FromWebContents(guest_web_contents()); |
60 DCHECK(menu_delegate); | 47 DCHECK(menu_delegate); |
61 | 48 |
62 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params); | 49 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params); |
63 | 50 |
64 // Pass it to embedder. | 51 // Pass it to embedder. |
65 int request_id = ++pending_context_menu_request_id_; | 52 int request_id = ++pending_context_menu_request_id_; |
66 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 53 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
67 scoped_ptr<base::ListValue> items = | 54 scoped_ptr<base::ListValue> items = |
68 MenuModelToValue(pending_menu_->menu_model()); | 55 MenuModelToValue(pending_menu_->menu_model()); |
69 args->Set(webview::kContextMenuItems, items.release()); | 56 args->Set(webview::kContextMenuItems, items.release()); |
70 args->SetInteger(webview::kRequestId, request_id); | 57 args->SetInteger(webview::kRequestId, request_id); |
71 web_view_guest()->DispatchEventToEmbedder( | 58 web_view_guest_->DispatchEventToEmbedder( |
72 new extensions::GuestViewBase::Event( | 59 new extensions::GuestViewBase::Event( |
73 webview::kEventContextMenu, args.Pass())); | 60 webview::kEventContextMenu, args.Pass())); |
74 return true; | 61 return true; |
75 } | 62 } |
76 | 63 |
77 // TODO(hanxi) Investigate which of these observers should move to the | 64 // TODO(hanxi) Investigate which of these observers should move to the |
78 // extension module in the future. | 65 // extension module in the future. |
79 void ChromeWebViewGuestDelegate::OnAttachWebViewHelpers( | 66 void ChromeWebViewGuestDelegate::OnAttachWebViewHelpers( |
80 content::WebContents* contents) { | 67 content::WebContents* contents) { |
81 // Create a zoom controller for the guest contents give it access to | 68 // Create a zoom controller for the guest contents give it access to |
(...skipping 11 matching lines...) Expand all Loading... |
93 #if defined(ENABLE_FULL_PRINTING) | 80 #if defined(ENABLE_FULL_PRINTING) |
94 printing::PrintViewManager::CreateForWebContents(contents); | 81 printing::PrintViewManager::CreateForWebContents(contents); |
95 printing::PrintPreviewMessageHandler::CreateForWebContents(contents); | 82 printing::PrintPreviewMessageHandler::CreateForWebContents(contents); |
96 #else | 83 #else |
97 printing::PrintViewManagerBasic::CreateForWebContents(contents); | 84 printing::PrintViewManagerBasic::CreateForWebContents(contents); |
98 #endif // defined(ENABLE_FULL_PRINTING) | 85 #endif // defined(ENABLE_FULL_PRINTING) |
99 #endif // defined(ENABLE_PRINTING) | 86 #endif // defined(ENABLE_PRINTING) |
100 PDFTabHelper::CreateForWebContents(contents); | 87 PDFTabHelper::CreateForWebContents(contents); |
101 } | 88 } |
102 | 89 |
103 void ChromeWebViewGuestDelegate::OnEmbedderDestroyed() { | |
104 // TODO(fsamuel): WebRequest event listeners for <webview> should survive | |
105 // reparenting of a <webview> within a single embedder. Right now, we keep | |
106 // around the browser state for the listener for the lifetime of the embedder. | |
107 // Ideally, the lifetime of the listeners should match the lifetime of the | |
108 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move | |
109 // the call to RemoveWebViewEventListenersOnIOThread back to | |
110 // WebViewGuest::WebContentsDestroyed. | |
111 content::BrowserThread::PostTask( | |
112 content::BrowserThread::IO, | |
113 FROM_HERE, | |
114 base::Bind( | |
115 &RemoveWebViewEventListenersOnIOThread, | |
116 web_view_guest()->browser_context(), | |
117 web_view_guest()->embedder_extension_id(), | |
118 web_view_guest()->embedder_render_process_id(), | |
119 web_view_guest()->view_instance_id())); | |
120 } | |
121 | |
122 void ChromeWebViewGuestDelegate::OnDidCommitProvisionalLoadForFrame( | 90 void ChromeWebViewGuestDelegate::OnDidCommitProvisionalLoadForFrame( |
123 bool is_main_frame) { | 91 bool is_main_frame) { |
124 // Update the current zoom factor for the new page. | 92 // Update the current zoom factor for the new page. |
125 ZoomController* zoom_controller = | 93 ZoomController* zoom_controller = |
126 ZoomController::FromWebContents(guest_web_contents()); | 94 ZoomController::FromWebContents(guest_web_contents()); |
127 DCHECK(zoom_controller); | 95 DCHECK(zoom_controller); |
128 current_zoom_factor_ = zoom_controller->GetZoomLevel(); | 96 current_zoom_factor_ = zoom_controller->GetZoomLevel(); |
129 if (is_main_frame) | 97 if (is_main_frame) |
130 chromevox_injected_ = false; | 98 chromevox_injected_ = false; |
131 } | 99 } |
(...skipping 11 matching lines...) Expand all Loading... |
143 | 111 |
144 void ChromeWebViewGuestDelegate::OnDocumentLoadedInFrame( | 112 void ChromeWebViewGuestDelegate::OnDocumentLoadedInFrame( |
145 content::RenderFrameHost* render_frame_host) { | 113 content::RenderFrameHost* render_frame_host) { |
146 if (!render_frame_host->GetParent()) | 114 if (!render_frame_host->GetParent()) |
147 InjectChromeVoxIfNeeded(render_frame_host->GetRenderViewHost()); | 115 InjectChromeVoxIfNeeded(render_frame_host->GetRenderViewHost()); |
148 } | 116 } |
149 | 117 |
150 void ChromeWebViewGuestDelegate::OnGuestDestroyed() { | 118 void ChromeWebViewGuestDelegate::OnGuestDestroyed() { |
151 // Clean up custom context menu items for this guest. | 119 // Clean up custom context menu items for this guest. |
152 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( | 120 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( |
153 Profile::FromBrowserContext(web_view_guest()->browser_context())); | 121 Profile::FromBrowserContext(web_view_guest_->browser_context())); |
154 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey( | 122 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey( |
155 web_view_guest()->embedder_extension_id(), | 123 web_view_guest_->embedder_extension_id(), |
156 web_view_guest()->view_instance_id())); | 124 web_view_guest_->view_instance_id())); |
157 } | 125 } |
158 | 126 |
159 // static | 127 // static |
160 scoped_ptr<base::ListValue> ChromeWebViewGuestDelegate::MenuModelToValue( | 128 scoped_ptr<base::ListValue> ChromeWebViewGuestDelegate::MenuModelToValue( |
161 const ui::SimpleMenuModel& menu_model) { | 129 const ui::SimpleMenuModel& menu_model) { |
162 scoped_ptr<base::ListValue> items(new base::ListValue()); | 130 scoped_ptr<base::ListValue> items(new base::ListValue()); |
163 for (int i = 0; i < menu_model.GetItemCount(); ++i) { | 131 for (int i = 0; i < menu_model.GetItemCount(); ++i) { |
164 base::DictionaryValue* item_value = new base::DictionaryValue(); | 132 base::DictionaryValue* item_value = new base::DictionaryValue(); |
165 // TODO(lazyboy): We need to expose some kind of enum equivalent of | 133 // TODO(lazyboy): We need to expose some kind of enum equivalent of |
166 // |command_id| instead of plain integers. | 134 // |command_id| instead of plain integers. |
167 item_value->SetInteger(webview::kMenuItemCommandId, | 135 item_value->SetInteger(webview::kMenuItemCommandId, |
168 menu_model.GetCommandIdAt(i)); | 136 menu_model.GetCommandIdAt(i)); |
169 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); | 137 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); |
170 items->Append(item_value); | 138 items->Append(item_value); |
171 } | 139 } |
172 return items.Pass(); | 140 return items.Pass(); |
173 } | 141 } |
174 | 142 |
175 void ChromeWebViewGuestDelegate::OnSetZoom(double zoom_factor) { | 143 void ChromeWebViewGuestDelegate::OnSetZoom(double zoom_factor) { |
176 ZoomController* zoom_controller = | 144 ZoomController* zoom_controller = |
177 ZoomController::FromWebContents(guest_web_contents()); | 145 ZoomController::FromWebContents(guest_web_contents()); |
178 DCHECK(zoom_controller); | 146 DCHECK(zoom_controller); |
179 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); | 147 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); |
180 zoom_controller->SetZoomLevel(zoom_level); | 148 zoom_controller->SetZoomLevel(zoom_level); |
181 | 149 |
182 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 150 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
183 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); | 151 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); |
184 args->SetDouble(webview::kNewZoomFactor, zoom_factor); | 152 args->SetDouble(webview::kNewZoomFactor, zoom_factor); |
185 web_view_guest()->DispatchEventToEmbedder( | 153 web_view_guest_->DispatchEventToEmbedder( |
186 new extensions::GuestViewBase::Event( | 154 new extensions::GuestViewBase::Event( |
187 webview::kEventZoomChange, args.Pass())); | 155 webview::kEventZoomChange, args.Pass())); |
188 current_zoom_factor_ = zoom_factor; | 156 current_zoom_factor_ = zoom_factor; |
189 } | 157 } |
190 | 158 |
191 void ChromeWebViewGuestDelegate::OnShowContextMenu( | 159 void ChromeWebViewGuestDelegate::OnShowContextMenu( |
192 int request_id, | 160 int request_id, |
193 const MenuItemVector* items) { | 161 const MenuItemVector* items) { |
194 if (!pending_menu_.get()) | 162 if (!pending_menu_.get()) |
195 return; | 163 return; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 accessibility_subscription_.reset(); | 195 accessibility_subscription_.reset(); |
228 } else if (details.notification_type == | 196 } else if (details.notification_type == |
229 chromeos::ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK) { | 197 chromeos::ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK) { |
230 if (details.enabled) | 198 if (details.enabled) |
231 InjectChromeVoxIfNeeded(guest_web_contents()->GetRenderViewHost()); | 199 InjectChromeVoxIfNeeded(guest_web_contents()->GetRenderViewHost()); |
232 else | 200 else |
233 chromevox_injected_ = false; | 201 chromevox_injected_ = false; |
234 } | 202 } |
235 } | 203 } |
236 #endif | 204 #endif |
OLD | NEW |