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

Side by Side Diff: chrome/browser/guest_view/web_view/chrome_web_view_guest_delegate.cc

Issue 1140173003: Allow whitelisted content scripts to be injected in WebViews. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@document_has_focus
Patch Set: Remove some no-longer-needed WebViewGuestDelegate interfaces Created 5 years, 7 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 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_helper.h" 9 #include "chrome/browser/favicon/favicon_helper.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 17 matching lines...) Expand all
28 #endif // defined(ENABLE_PRINT_PREVIEW) 28 #endif // defined(ENABLE_PRINT_PREVIEW)
29 #endif // defined(ENABLE_PRINTING) 29 #endif // defined(ENABLE_PRINTING)
30 30
31 using guest_view::GuestViewEvent; 31 using guest_view::GuestViewEvent;
32 32
33 namespace extensions { 33 namespace extensions {
34 34
35 ChromeWebViewGuestDelegate::ChromeWebViewGuestDelegate( 35 ChromeWebViewGuestDelegate::ChromeWebViewGuestDelegate(
36 WebViewGuest* web_view_guest) 36 WebViewGuest* web_view_guest)
37 : pending_context_menu_request_id_(0), 37 : pending_context_menu_request_id_(0),
38 chromevox_injected_(false),
39 web_view_guest_(web_view_guest), 38 web_view_guest_(web_view_guest),
40 weak_ptr_factory_(this) { 39 weak_ptr_factory_(this) {
41 } 40 }
42 41
43 ChromeWebViewGuestDelegate::~ChromeWebViewGuestDelegate() { 42 ChromeWebViewGuestDelegate::~ChromeWebViewGuestDelegate() {
44 } 43 }
45 44
46 bool ChromeWebViewGuestDelegate::HandleContextMenu( 45 bool ChromeWebViewGuestDelegate::HandleContextMenu(
47 const content::ContextMenuParams& params) { 46 const content::ContextMenuParams& params) {
48 ContextMenuDelegate* menu_delegate = 47 ContextMenuDelegate* menu_delegate =
(...skipping 27 matching lines...) Expand all
76 #else 75 #else
77 printing::PrintViewManagerBasic::CreateForWebContents(contents); 76 printing::PrintViewManagerBasic::CreateForWebContents(contents);
78 #endif // defined(ENABLE_PRINT_PREVIEW) 77 #endif // defined(ENABLE_PRINT_PREVIEW)
79 #endif // defined(ENABLE_PRINTING) 78 #endif // defined(ENABLE_PRINTING)
80 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient( 79 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
81 contents, 80 contents,
82 scoped_ptr<pdf::PDFWebContentsHelperClient>( 81 scoped_ptr<pdf::PDFWebContentsHelperClient>(
83 new ChromePDFWebContentsHelperClient())); 82 new ChromePDFWebContentsHelperClient()));
84 } 83 }
85 84
86 void ChromeWebViewGuestDelegate::OnDidCommitProvisionalLoadForFrame(
87 bool is_main_frame) {
88 if (is_main_frame)
89 chromevox_injected_ = false;
90 }
91
92 void ChromeWebViewGuestDelegate::OnDidInitialize() {
93 #if defined(OS_CHROMEOS)
94 chromeos::AccessibilityManager* accessibility_manager =
95 chromeos::AccessibilityManager::Get();
96 CHECK(accessibility_manager);
97 accessibility_subscription_ = accessibility_manager->RegisterCallback(
98 base::Bind(&ChromeWebViewGuestDelegate::OnAccessibilityStatusChanged,
99 weak_ptr_factory_.GetWeakPtr()));
100 #endif
101 }
102
103 void ChromeWebViewGuestDelegate::OnDocumentLoadedInFrame(
104 content::RenderFrameHost* render_frame_host) {
105 if (!render_frame_host->GetParent())
106 InjectChromeVoxIfNeeded(render_frame_host->GetRenderViewHost());
107 }
108
109 void ChromeWebViewGuestDelegate::OnGuestDestroyed() { 85 void ChromeWebViewGuestDelegate::OnGuestDestroyed() {
110 // Clean up custom context menu items for this guest. 86 // Clean up custom context menu items for this guest.
111 MenuManager* menu_manager = MenuManager::Get( 87 MenuManager* menu_manager = MenuManager::Get(
112 Profile::FromBrowserContext(web_view_guest()->browser_context())); 88 Profile::FromBrowserContext(web_view_guest()->browser_context()));
113 menu_manager->RemoveAllContextItems(MenuItem::ExtensionKey( 89 menu_manager->RemoveAllContextItems(MenuItem::ExtensionKey(
114 web_view_guest()->owner_host(), 90 web_view_guest()->owner_host(),
115 web_view_guest()->view_instance_id())); 91 web_view_guest()->view_instance_id()));
116 } 92 }
117 93
118 // static 94 // static
(...skipping 23 matching lines...) Expand all
142 return; 118 return;
143 119
144 // TODO(lazyboy): Implement. 120 // TODO(lazyboy): Implement.
145 DCHECK(!items); 121 DCHECK(!items);
146 122
147 ContextMenuDelegate* menu_delegate = 123 ContextMenuDelegate* menu_delegate =
148 ContextMenuDelegate::FromWebContents(guest_web_contents()); 124 ContextMenuDelegate::FromWebContents(guest_web_contents());
149 menu_delegate->ShowMenu(pending_menu_.Pass()); 125 menu_delegate->ShowMenu(pending_menu_.Pass());
150 } 126 }
151 127
152 void ChromeWebViewGuestDelegate::InjectChromeVoxIfNeeded(
153 content::RenderViewHost* render_view_host) {
154 #if defined(OS_CHROMEOS)
155 if (!chromevox_injected_) {
156 chromeos::AccessibilityManager* manager =
157 chromeos::AccessibilityManager::Get();
158 if (manager && manager->IsSpokenFeedbackEnabled()) {
159 manager->InjectChromeVox(render_view_host);
160 chromevox_injected_ = true;
161 }
162 }
163 #endif
164 }
165
166 #if defined(OS_CHROMEOS)
167 void ChromeWebViewGuestDelegate::OnAccessibilityStatusChanged(
168 const chromeos::AccessibilityStatusEventDetails& details) {
169 if (details.notification_type == chromeos::ACCESSIBILITY_MANAGER_SHUTDOWN) {
170 accessibility_subscription_.reset();
171 } else if (details.notification_type ==
172 chromeos::ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK) {
173 if (details.enabled)
174 InjectChromeVoxIfNeeded(guest_web_contents()->GetRenderViewHost());
175 else
176 chromevox_injected_ = false;
177 }
178 }
179 #endif
180
181 } // namespace extensions 128 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698