| 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 namespace extensions { |
| 30 |
| 29 ChromeWebViewGuestDelegate::ChromeWebViewGuestDelegate( | 31 ChromeWebViewGuestDelegate::ChromeWebViewGuestDelegate( |
| 30 extensions::WebViewGuest* web_view_guest) | 32 WebViewGuest* web_view_guest) |
| 31 : pending_context_menu_request_id_(0), | 33 : pending_context_menu_request_id_(0), |
| 32 chromevox_injected_(false), | 34 chromevox_injected_(false), |
| 33 current_zoom_factor_(1.0), | 35 current_zoom_factor_(1.0), |
| 34 web_view_guest_(web_view_guest), | 36 web_view_guest_(web_view_guest), |
| 35 weak_ptr_factory_(this) { | 37 weak_ptr_factory_(this) { |
| 36 } | 38 } |
| 37 | 39 |
| 38 ChromeWebViewGuestDelegate::~ChromeWebViewGuestDelegate() { | 40 ChromeWebViewGuestDelegate::~ChromeWebViewGuestDelegate() { |
| 39 } | 41 } |
| 40 | 42 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 51 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params); | 53 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params); |
| 52 | 54 |
| 53 // Pass it to embedder. | 55 // Pass it to embedder. |
| 54 int request_id = ++pending_context_menu_request_id_; | 56 int request_id = ++pending_context_menu_request_id_; |
| 55 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 57 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 56 scoped_ptr<base::ListValue> items = | 58 scoped_ptr<base::ListValue> items = |
| 57 MenuModelToValue(pending_menu_->menu_model()); | 59 MenuModelToValue(pending_menu_->menu_model()); |
| 58 args->Set(webview::kContextMenuItems, items.release()); | 60 args->Set(webview::kContextMenuItems, items.release()); |
| 59 args->SetInteger(webview::kRequestId, request_id); | 61 args->SetInteger(webview::kRequestId, request_id); |
| 60 web_view_guest()->DispatchEventToEmbedder( | 62 web_view_guest()->DispatchEventToEmbedder( |
| 61 new extensions::GuestViewBase::Event( | 63 new GuestViewBase::Event(webview::kEventContextMenu, args.Pass())); |
| 62 webview::kEventContextMenu, args.Pass())); | |
| 63 return true; | 64 return true; |
| 64 } | 65 } |
| 65 | 66 |
| 66 // TODO(hanxi) Investigate which of these observers should move to the | 67 // TODO(hanxi) Investigate which of these observers should move to the |
| 67 // extension module in the future. | 68 // extension module in the future. |
| 68 void ChromeWebViewGuestDelegate::OnAttachWebViewHelpers( | 69 void ChromeWebViewGuestDelegate::OnAttachWebViewHelpers( |
| 69 content::WebContents* contents) { | 70 content::WebContents* contents) { |
| 70 // Create a zoom controller for the guest contents give it access to | 71 // Create a zoom controller for the guest contents give it access to |
| 71 // GetZoomLevel() and and SetZoomLevel() in WebViewGuest. | 72 // GetZoomLevel() and and SetZoomLevel() in WebViewGuest. |
| 72 // TODO(wjmaclean) This currently uses the same HostZoomMap as the browser | 73 // TODO(wjmaclean) This currently uses the same HostZoomMap as the browser |
| 73 // context, but we eventually want to isolate the guest contents from zoom | 74 // context, but we eventually want to isolate the guest contents from zoom |
| 74 // changes outside the guest (e.g. in the main browser), so we should | 75 // changes outside the guest (e.g. in the main browser), so we should |
| 75 // create a separate HostZoomMap for the guest. | 76 // create a separate HostZoomMap for the guest. |
| 76 ZoomController::CreateForWebContents(contents); | 77 ZoomController::CreateForWebContents(contents); |
| 77 | 78 |
| 78 FaviconTabHelper::CreateForWebContents(contents); | 79 FaviconTabHelper::CreateForWebContents(contents); |
| 79 extensions::ChromeExtensionWebContentsObserver:: | 80 ChromeExtensionWebContentsObserver::CreateForWebContents(contents); |
| 80 CreateForWebContents(contents); | |
| 81 #if defined(ENABLE_PRINTING) | 81 #if defined(ENABLE_PRINTING) |
| 82 #if defined(ENABLE_FULL_PRINTING) | 82 #if defined(ENABLE_FULL_PRINTING) |
| 83 printing::PrintViewManager::CreateForWebContents(contents); | 83 printing::PrintViewManager::CreateForWebContents(contents); |
| 84 printing::PrintPreviewMessageHandler::CreateForWebContents(contents); | 84 printing::PrintPreviewMessageHandler::CreateForWebContents(contents); |
| 85 #else | 85 #else |
| 86 printing::PrintViewManagerBasic::CreateForWebContents(contents); | 86 printing::PrintViewManagerBasic::CreateForWebContents(contents); |
| 87 #endif // defined(ENABLE_FULL_PRINTING) | 87 #endif // defined(ENABLE_FULL_PRINTING) |
| 88 #endif // defined(ENABLE_PRINTING) | 88 #endif // defined(ENABLE_PRINTING) |
| 89 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient( | 89 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient( |
| 90 contents, | 90 contents, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 void ChromeWebViewGuestDelegate::OnGuestReady() { | 138 void ChromeWebViewGuestDelegate::OnGuestReady() { |
| 139 ZoomController* zoom_controller = | 139 ZoomController* zoom_controller = |
| 140 ZoomController::FromWebContents(guest_web_contents()); | 140 ZoomController::FromWebContents(guest_web_contents()); |
| 141 DCHECK(zoom_controller); | 141 DCHECK(zoom_controller); |
| 142 zoom_controller->SetZoomMode(ZoomController::ZOOM_MODE_ISOLATED); | 142 zoom_controller->SetZoomMode(ZoomController::ZOOM_MODE_ISOLATED); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void ChromeWebViewGuestDelegate::OnGuestDestroyed() { | 145 void ChromeWebViewGuestDelegate::OnGuestDestroyed() { |
| 146 // Clean up custom context menu items for this guest. | 146 // Clean up custom context menu items for this guest. |
| 147 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( | 147 MenuManager* menu_manager = MenuManager::Get( |
| 148 Profile::FromBrowserContext(web_view_guest()->browser_context())); | 148 Profile::FromBrowserContext(web_view_guest()->browser_context())); |
| 149 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey( | 149 menu_manager->RemoveAllContextItems(MenuItem::ExtensionKey( |
| 150 web_view_guest()->embedder_extension_id(), | 150 web_view_guest()->embedder_extension_id(), |
| 151 web_view_guest()->view_instance_id())); | 151 web_view_guest()->view_instance_id())); |
| 152 } | 152 } |
| 153 | 153 |
| 154 // static | 154 // static |
| 155 scoped_ptr<base::ListValue> ChromeWebViewGuestDelegate::MenuModelToValue( | 155 scoped_ptr<base::ListValue> ChromeWebViewGuestDelegate::MenuModelToValue( |
| 156 const ui::SimpleMenuModel& menu_model) { | 156 const ui::SimpleMenuModel& menu_model) { |
| 157 scoped_ptr<base::ListValue> items(new base::ListValue()); | 157 scoped_ptr<base::ListValue> items(new base::ListValue()); |
| 158 for (int i = 0; i < menu_model.GetItemCount(); ++i) { | 158 for (int i = 0; i < menu_model.GetItemCount(); ++i) { |
| 159 base::DictionaryValue* item_value = new base::DictionaryValue(); | 159 base::DictionaryValue* item_value = new base::DictionaryValue(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 171 ZoomController* zoom_controller = | 171 ZoomController* zoom_controller = |
| 172 ZoomController::FromWebContents(guest_web_contents()); | 172 ZoomController::FromWebContents(guest_web_contents()); |
| 173 DCHECK(zoom_controller); | 173 DCHECK(zoom_controller); |
| 174 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); | 174 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); |
| 175 zoom_controller->SetZoomLevel(zoom_level); | 175 zoom_controller->SetZoomLevel(zoom_level); |
| 176 | 176 |
| 177 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 177 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 178 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); | 178 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); |
| 179 args->SetDouble(webview::kNewZoomFactor, zoom_factor); | 179 args->SetDouble(webview::kNewZoomFactor, zoom_factor); |
| 180 web_view_guest()->DispatchEventToEmbedder( | 180 web_view_guest()->DispatchEventToEmbedder( |
| 181 new extensions::GuestViewBase::Event( | 181 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass())); |
| 182 webview::kEventZoomChange, args.Pass())); | |
| 183 current_zoom_factor_ = zoom_factor; | 182 current_zoom_factor_ = zoom_factor; |
| 184 } | 183 } |
| 185 | 184 |
| 186 void ChromeWebViewGuestDelegate::OnShowContextMenu( | 185 void ChromeWebViewGuestDelegate::OnShowContextMenu( |
| 187 int request_id, | 186 int request_id, |
| 188 const MenuItemVector* items) { | 187 const MenuItemVector* items) { |
| 189 if (!pending_menu_.get()) | 188 if (!pending_menu_.get()) |
| 190 return; | 189 return; |
| 191 | 190 |
| 192 // Make sure this was the correct request. | 191 // Make sure this was the correct request. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 chromevox_injected_ = false; | 227 chromevox_injected_ = false; |
| 229 } | 228 } |
| 230 } | 229 } |
| 231 #endif | 230 #endif |
| 232 | 231 |
| 233 void ChromeWebViewGuestDelegate::OnZoomChanged( | 232 void ChromeWebViewGuestDelegate::OnZoomChanged( |
| 234 const ZoomController::ZoomChangedEventData& data) { | 233 const ZoomController::ZoomChangedEventData& data) { |
| 235 ZoomController::FromWebContents(guest_web_contents())-> | 234 ZoomController::FromWebContents(guest_web_contents())-> |
| 236 SetZoomLevel(data.new_zoom_level); | 235 SetZoomLevel(data.new_zoom_level); |
| 237 } | 236 } |
| 237 |
| 238 } // namespace extensions |
| OLD | NEW |