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

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

Issue 347113002: Refactor PluginPermissionHelper as WebViewPermissionHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes are made. Created 6 years, 5 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 #include "chrome/browser/guest_view/web_view/web_view_guest.h" 5 #include "chrome/browser/guest_view/web_view/web_view_guest.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
12 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 11 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
13 #include "chrome/browser/extensions/api/web_view/web_view_internal_api.h" 12 #include "chrome/browser/extensions/api/web_view/web_view_internal_api.h"
14 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" 13 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
15 #include "chrome/browser/extensions/menu_manager.h" 14 #include "chrome/browser/extensions/menu_manager.h"
16 #include "chrome/browser/extensions/script_executor.h" 15 #include "chrome/browser/extensions/script_executor.h"
17 #include "chrome/browser/favicon/favicon_tab_helper.h" 16 #include "chrome/browser/favicon/favicon_tab_helper.h"
18 #include "chrome/browser/geolocation/geolocation_permission_context.h"
19 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
20 #include "chrome/browser/guest_view/guest_view_constants.h" 17 #include "chrome/browser/guest_view/guest_view_constants.h"
21 #include "chrome/browser/guest_view/guest_view_manager.h" 18 #include "chrome/browser/guest_view/guest_view_manager.h"
22 #include "chrome/browser/guest_view/web_view/web_view_constants.h" 19 #include "chrome/browser/guest_view/web_view/web_view_constants.h"
20 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h"
23 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" 21 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h"
24 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" 22 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h"
25 #include "chrome/browser/renderer_context_menu/context_menu_delegate.h" 23 #include "chrome/browser/renderer_context_menu/context_menu_delegate.h"
26 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" 24 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
27 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" 25 #include "chrome/browser/ui/pdf/pdf_tab_helper.h"
28 #include "chrome/browser/ui/zoom/zoom_controller.h" 26 #include "chrome/browser/ui/zoom/zoom_controller.h"
29 #include "chrome/common/chrome_version_info.h" 27 #include "chrome/common/chrome_version_info.h"
30 #include "chrome/common/render_messages.h" 28 #include "chrome/common/render_messages.h"
31 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/child_process_security_policy.h" 30 #include "content/public/browser/child_process_security_policy.h"
(...skipping 25 matching lines...) Expand all
58 56
59 #if defined(ENABLE_PRINTING) 57 #if defined(ENABLE_PRINTING)
60 #if defined(ENABLE_FULL_PRINTING) 58 #if defined(ENABLE_FULL_PRINTING)
61 #include "chrome/browser/printing/print_preview_message_handler.h" 59 #include "chrome/browser/printing/print_preview_message_handler.h"
62 #include "chrome/browser/printing/print_view_manager.h" 60 #include "chrome/browser/printing/print_view_manager.h"
63 #else 61 #else
64 #include "chrome/browser/printing/print_view_manager_basic.h" 62 #include "chrome/browser/printing/print_view_manager_basic.h"
65 #endif // defined(ENABLE_FULL_PRINTING) 63 #endif // defined(ENABLE_FULL_PRINTING)
66 #endif // defined(ENABLE_PRINTING) 64 #endif // defined(ENABLE_PRINTING)
67 65
68 #if defined(ENABLE_PLUGINS) && !defined(OS_ANDROID)
69 #include "chrome/browser/guest_view/web_view/plugin_permission_helper.h"
70 #endif
71
72 #if defined(OS_CHROMEOS) 66 #if defined(OS_CHROMEOS)
73 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" 67 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
74 #endif 68 #endif
75 69
76 using base::UserMetricsAction; 70 using base::UserMetricsAction;
77 using content::RenderFrameHost; 71 using content::RenderFrameHost;
78 using content::ResourceType; 72 using content::ResourceType;
79 using content::WebContents; 73 using content::WebContents;
80 74
81 namespace { 75 namespace {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return "killed"; 108 return "killed";
115 case base::TERMINATION_STATUS_PROCESS_CRASHED: 109 case base::TERMINATION_STATUS_PROCESS_CRASHED:
116 return "crashed"; 110 return "crashed";
117 case base::TERMINATION_STATUS_MAX_ENUM: 111 case base::TERMINATION_STATUS_MAX_ENUM:
118 break; 112 break;
119 } 113 }
120 NOTREACHED() << "Unknown Termination Status."; 114 NOTREACHED() << "Unknown Termination Status.";
121 return "unknown"; 115 return "unknown";
122 } 116 }
123 117
124 static std::string PermissionTypeToString(WebViewPermissionType type) {
125 switch (type) {
126 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD:
127 return webview::kPermissionTypeDownload;
128 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM:
129 return webview::kPermissionTypeFileSystem;
130 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
131 return webview::kPermissionTypeGeolocation;
132 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
133 return webview::kPermissionTypeDialog;
134 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
135 return webview::kPermissionTypeLoadPlugin;
136 case WEB_VIEW_PERMISSION_TYPE_MEDIA:
137 return webview::kPermissionTypeMedia;
138 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW:
139 return webview::kPermissionTypeNewWindow;
140 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK:
141 return webview::kPermissionTypePointerLock;
142 default:
143 NOTREACHED();
144 return std::string();
145 }
146 }
147
148 std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) { 118 std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) {
149 const std::string& partition_id = site_url.query(); 119 const std::string& partition_id = site_url.query();
150 bool persist_storage = site_url.path().find("persist") != std::string::npos; 120 bool persist_storage = site_url.path().find("persist") != std::string::npos;
151 return (persist_storage ? webview::kPersistPrefix : "") + partition_id; 121 return (persist_storage ? webview::kPersistPrefix : "") + partition_id;
152 } 122 }
153 123
154 void RemoveWebViewEventListenersOnIOThread( 124 void RemoveWebViewEventListenersOnIOThread(
155 void* profile, 125 void* profile,
156 const std::string& extension_id, 126 const std::string& extension_id,
157 int embedder_process_id, 127 int embedder_process_id,
158 int view_instance_id) { 128 int view_instance_id) {
159 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 129 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
160 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( 130 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners(
161 profile, 131 profile,
162 extension_id, 132 extension_id,
163 embedder_process_id, 133 embedder_process_id,
164 view_instance_id); 134 view_instance_id);
165 } 135 }
166 136
167 void AttachWebViewHelpers(WebContents* contents) {
168 // Create a zoom controller for the guest contents give it access to
169 // GetZoomLevel() and and SetZoomLevel() in WebViewGuest.
170 // TODO(wjmaclean) This currently uses the same HostZoomMap as the browser
171 // context, but we eventually want to isolate the guest contents from zoom
172 // changes outside the guest (e.g. in the main browser), so we should
173 // create a separate HostZoomMap for the guest.
174 ZoomController::CreateForWebContents(contents);
175
176 FaviconTabHelper::CreateForWebContents(contents);
177 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
178 contents);
179 #if defined(ENABLE_PLUGINS) && !defined(OS_ANDROID)
180 PluginPermissionHelper::CreateForWebContents(contents);
181 #endif
182 #if defined(ENABLE_PRINTING)
183 #if defined(ENABLE_FULL_PRINTING)
184 printing::PrintViewManager::CreateForWebContents(contents);
185 printing::PrintPreviewMessageHandler::CreateForWebContents(contents);
186 #else
187 printing::PrintViewManagerBasic::CreateForWebContents(contents);
188 #endif // defined(ENABLE_FULL_PRINTING)
189 #endif // defined(ENABLE_PRINTING)
190 PDFTabHelper::CreateForWebContents(contents);
191 }
192
193 void ParsePartitionParam(const base::DictionaryValue& create_params, 137 void ParsePartitionParam(const base::DictionaryValue& create_params,
194 std::string* storage_partition_id, 138 std::string* storage_partition_id,
195 bool* persist_storage) { 139 bool* persist_storage) {
196 std::string partition_str; 140 std::string partition_str;
197 if (!create_params.GetString(webview::kStoragePartitionId, &partition_str)) { 141 if (!create_params.GetString(webview::kStoragePartitionId, &partition_str)) {
198 return; 142 return;
199 } 143 }
200 144
201 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on 145 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on
202 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely 146 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely
(...skipping 15 matching lines...) Expand all
218 *persist_storage = false; 162 *persist_storage = false;
219 } 163 }
220 } 164 }
221 165
222 } // namespace 166 } // namespace
223 167
224 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, 168 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context,
225 int guest_instance_id) 169 int guest_instance_id)
226 : GuestView<WebViewGuest>(browser_context, guest_instance_id), 170 : GuestView<WebViewGuest>(browser_context, guest_instance_id),
227 pending_context_menu_request_id_(0), 171 pending_context_menu_request_id_(0),
228 next_permission_request_id_(0),
229 is_overriding_user_agent_(false), 172 is_overriding_user_agent_(false),
230 main_frame_id_(0), 173 main_frame_id_(0),
231 chromevox_injected_(false), 174 chromevox_injected_(false),
232 find_helper_(this), 175 find_helper_(this),
233 javascript_dialog_helper_(this) { 176 javascript_dialog_helper_(this) {
234 } 177 }
235 178
236 // static 179 // static
237 bool WebViewGuest::GetGuestPartitionConfigForSite( 180 bool WebViewGuest::GetGuestPartitionConfigForSite(
238 const GURL& site, 181 const GURL& site,
(...skipping 23 matching lines...) Expand all
262 // static 205 // static
263 int WebViewGuest::GetViewInstanceId(WebContents* contents) { 206 int WebViewGuest::GetViewInstanceId(WebContents* contents) {
264 WebViewGuest* guest = FromWebContents(contents); 207 WebViewGuest* guest = FromWebContents(contents);
265 if (!guest) 208 if (!guest)
266 return guestview::kInstanceIDNone; 209 return guestview::kInstanceIDNone;
267 210
268 return guest->view_instance_id(); 211 return guest->view_instance_id();
269 } 212 }
270 213
271 // static 214 // static
272 void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info,
273 bool allow) {
274 if (allow) {
275 // Note that |allow| == true means the embedder explicitly allowed the
276 // request. For some requests they might still fail. An example of such
277 // scenario would be: an embedder allows geolocation request but doesn't
278 // have geolocation access on its own.
279 switch (info.permission_type) {
280 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD:
281 content::RecordAction(
282 UserMetricsAction("WebView.PermissionAllow.Download"));
283 break;
284 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM:
285 content::RecordAction(
286 UserMetricsAction("WebView.PermissionAllow.FileSystem"));
287 break;
288 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
289 content::RecordAction(
290 UserMetricsAction("WebView.PermissionAllow.Geolocation"));
291 break;
292 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
293 content::RecordAction(
294 UserMetricsAction("WebView.PermissionAllow.JSDialog"));
295 break;
296 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
297 content::RecordAction(
298 UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad"));
299 case WEB_VIEW_PERMISSION_TYPE_MEDIA:
300 content::RecordAction(
301 UserMetricsAction("WebView.PermissionAllow.Media"));
302 break;
303 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW:
304 content::RecordAction(
305 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow"));
306 break;
307 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK:
308 content::RecordAction(
309 UserMetricsAction("WebView.PermissionAllow.PointerLock"));
310 break;
311 default:
312 break;
313 }
314 } else {
315 switch (info.permission_type) {
316 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD:
317 content::RecordAction(
318 UserMetricsAction("WebView.PermissionDeny.Download"));
319 break;
320 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM:
321 content::RecordAction(
322 UserMetricsAction("WebView.PermissionDeny.FileSystem"));
323 break;
324 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
325 content::RecordAction(
326 UserMetricsAction("WebView.PermissionDeny.Geolocation"));
327 break;
328 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
329 content::RecordAction(
330 UserMetricsAction("WebView.PermissionDeny.JSDialog"));
331 break;
332 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
333 content::RecordAction(
334 UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad"));
335 break;
336 case WEB_VIEW_PERMISSION_TYPE_MEDIA:
337 content::RecordAction(
338 UserMetricsAction("WebView.PermissionDeny.Media"));
339 break;
340 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW:
341 content::RecordAction(
342 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow"));
343 break;
344 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK:
345 content::RecordAction(
346 UserMetricsAction("WebView.PermissionDeny.PointerLock"));
347 break;
348 default:
349 break;
350 }
351 }
352 }
353
354 // static
355 scoped_ptr<base::ListValue> WebViewGuest::MenuModelToValue( 215 scoped_ptr<base::ListValue> WebViewGuest::MenuModelToValue(
356 const ui::SimpleMenuModel& menu_model) { 216 const ui::SimpleMenuModel& menu_model) {
357 scoped_ptr<base::ListValue> items(new base::ListValue()); 217 scoped_ptr<base::ListValue> items(new base::ListValue());
358 for (int i = 0; i < menu_model.GetItemCount(); ++i) { 218 for (int i = 0; i < menu_model.GetItemCount(); ++i) {
359 base::DictionaryValue* item_value = new base::DictionaryValue(); 219 base::DictionaryValue* item_value = new base::DictionaryValue();
360 // TODO(lazyboy): We need to expose some kind of enum equivalent of 220 // TODO(lazyboy): We need to expose some kind of enum equivalent of
361 // |command_id| instead of plain integers. 221 // |command_id| instead of plain integers.
362 item_value->SetInteger(webview::kMenuItemCommandId, 222 item_value->SetInteger(webview::kMenuItemCommandId,
363 menu_model.GetCommandIdAt(i)); 223 menu_model.GetCommandIdAt(i));
364 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); 224 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 chromeos::AccessibilityManager::Get(); 345 chromeos::AccessibilityManager::Get();
486 CHECK(accessibility_manager); 346 CHECK(accessibility_manager);
487 accessibility_subscription_ = accessibility_manager->RegisterCallback( 347 accessibility_subscription_ = accessibility_manager->RegisterCallback(
488 base::Bind(&WebViewGuest::OnAccessibilityStatusChanged, 348 base::Bind(&WebViewGuest::OnAccessibilityStatusChanged,
489 base::Unretained(this))); 349 base::Unretained(this)));
490 #endif 350 #endif
491 351
492 AttachWebViewHelpers(guest_web_contents()); 352 AttachWebViewHelpers(guest_web_contents());
493 } 353 }
494 354
355 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) {
356 // Create a zoom controller for the guest contents give it access to
357 // GetZoomLevel() and and SetZoomLevel() in WebViewGuest.
358 // TODO(wjmaclean) This currently uses the same HostZoomMap as the browser
359 // context, but we eventually want to isolate the guest contents from zoom
360 // changes outside the guest (e.g. in the main browser), so we should
361 // create a separate HostZoomMap for the guest.
362 ZoomController::CreateForWebContents(contents);
363
364 FaviconTabHelper::CreateForWebContents(contents);
365 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
366 contents);
367 #if defined(ENABLE_PRINTING)
368 #if defined(ENABLE_FULL_PRINTING)
369 printing::PrintViewManager::CreateForWebContents(contents);
370 printing::PrintPreviewMessageHandler::CreateForWebContents(contents);
371 #else
372 printing::PrintViewManagerBasic::CreateForWebContents(contents);
373 #endif // defined(ENABLE_FULL_PRINTING)
374 #endif // defined(ENABLE_PRINTING)
375 PDFTabHelper::CreateForWebContents(contents);
376 web_view_permission_helper_.reset(new WebViewPermissionHelper(this));
377 }
495 378
496 void WebViewGuest::DidStopLoading() { 379 void WebViewGuest::DidStopLoading() {
497 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 380 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
498 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); 381 DispatchEventToEmbedder(
382 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass()));
499 } 383 }
500 384
501 void WebViewGuest::EmbedderDestroyed() { 385 void WebViewGuest::EmbedderDestroyed() {
502 // TODO(fsamuel): WebRequest event listeners for <webview> should survive 386 // TODO(fsamuel): WebRequest event listeners for <webview> should survive
503 // reparenting of a <webview> within a single embedder. Right now, we keep 387 // reparenting of a <webview> within a single embedder. Right now, we keep
504 // around the browser state for the listener for the lifetime of the embedder. 388 // around the browser state for the listener for the lifetime of the embedder.
505 // Ideally, the lifetime of the listeners should match the lifetime of the 389 // Ideally, the lifetime of the listeners should match the lifetime of the
506 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move 390 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move
507 // the call to RemoveWebViewEventListenersOnIOThread back to 391 // the call to RemoveWebViewEventListenersOnIOThread back to
508 // WebViewGuest::WebContentsDestroyed. 392 // WebViewGuest::WebContentsDestroyed.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 int32 level, 424 int32 level,
541 const base::string16& message, 425 const base::string16& message,
542 int32 line_no, 426 int32 line_no,
543 const base::string16& source_id) { 427 const base::string16& source_id) {
544 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 428 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
545 // Log levels are from base/logging.h: LogSeverity. 429 // Log levels are from base/logging.h: LogSeverity.
546 args->SetInteger(webview::kLevel, level); 430 args->SetInteger(webview::kLevel, level);
547 args->SetString(webview::kMessage, message); 431 args->SetString(webview::kMessage, message);
548 args->SetInteger(webview::kLine, line_no); 432 args->SetInteger(webview::kLine, line_no);
549 args->SetString(webview::kSourceId, source_id); 433 args->SetString(webview::kSourceId, source_id);
550 DispatchEvent( 434 DispatchEventToEmbedder(
551 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass())); 435 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass()));
552 return true; 436 return true;
553 } 437 }
554 438
555 void WebViewGuest::CloseContents(WebContents* source) { 439 void WebViewGuest::CloseContents(WebContents* source) {
556 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 440 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
557 DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass())); 441 DispatchEventToEmbedder(
442 new GuestViewBase::Event(webview::kEventClose, args.Pass()));
558 } 443 }
559 444
560 void WebViewGuest::FindReply(WebContents* source, 445 void WebViewGuest::FindReply(WebContents* source,
561 int request_id, 446 int request_id,
562 int number_of_matches, 447 int number_of_matches,
563 const gfx::Rect& selection_rect, 448 const gfx::Rect& selection_rect,
564 int active_match_ordinal, 449 int active_match_ordinal,
565 bool final_update) { 450 bool final_update) {
566 find_helper_.FindReply(request_id, number_of_matches, selection_rect, 451 find_helper_.FindReply(request_id, number_of_matches, selection_rect,
567 active_match_ordinal, final_update); 452 active_match_ordinal, final_update);
568 } 453 }
569 454
570 bool WebViewGuest::HandleContextMenu( 455 bool WebViewGuest::HandleContextMenu(
571 const content::ContextMenuParams& params) { 456 const content::ContextMenuParams& params) {
572 ContextMenuDelegate* menu_delegate = 457 ContextMenuDelegate* menu_delegate =
573 ContextMenuDelegate::FromWebContents(guest_web_contents()); 458 ContextMenuDelegate::FromWebContents(guest_web_contents());
574 DCHECK(menu_delegate); 459 DCHECK(menu_delegate);
575 460
576 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params); 461 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params);
577 462
578 // Pass it to embedder. 463 // Pass it to embedder.
579 int request_id = ++pending_context_menu_request_id_; 464 int request_id = ++pending_context_menu_request_id_;
580 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 465 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
581 scoped_ptr<base::ListValue> items = 466 scoped_ptr<base::ListValue> items =
582 MenuModelToValue(pending_menu_->menu_model()); 467 MenuModelToValue(pending_menu_->menu_model());
583 args->Set(webview::kContextMenuItems, items.release()); 468 args->Set(webview::kContextMenuItems, items.release());
584 args->SetInteger(webview::kRequestId, request_id); 469 args->SetInteger(webview::kRequestId, request_id);
585 DispatchEvent(new GuestViewBase::Event(webview::kEventContextMenu, 470 DispatchEventToEmbedder(
586 args.Pass())); 471 new GuestViewBase::Event(webview::kEventContextMenu, args.Pass()));
587 return true; 472 return true;
588 } 473 }
589 474
590 void WebViewGuest::HandleKeyboardEvent( 475 void WebViewGuest::HandleKeyboardEvent(
591 WebContents* source, 476 WebContents* source,
592 const content::NativeWebKeyboardEvent& event) { 477 const content::NativeWebKeyboardEvent& event) {
593 if (!attached()) 478 if (!attached())
594 return; 479 return;
595 480
596 if (HandleKeyboardShortcuts(event)) 481 if (HandleKeyboardShortcuts(event))
597 return; 482 return;
598 483
599 // Send the unhandled keyboard events back to the embedder to reprocess them. 484 // Send the unhandled keyboard events back to the embedder to reprocess them.
600 // TODO(fsamuel): This introduces the possibility of out-of-order keyboard 485 // TODO(fsamuel): This introduces the possibility of out-of-order keyboard
601 // events because the guest may be arbitrarily delayed when responding to 486 // events because the guest may be arbitrarily delayed when responding to
602 // keyboard events. In that time, the embedder may have received and processed 487 // keyboard events. In that time, the embedder may have received and processed
603 // additional key events. This needs to be fixed as soon as possible. 488 // additional key events. This needs to be fixed as soon as possible.
604 // See http://crbug.com/229882. 489 // See http://crbug.com/229882.
605 embedder_web_contents()->GetDelegate()->HandleKeyboardEvent( 490 embedder_web_contents()->GetDelegate()->HandleKeyboardEvent(
606 web_contents(), event); 491 web_contents(), event);
607 } 492 }
608 493
609 void WebViewGuest::LoadProgressChanged(content::WebContents* source, 494 void WebViewGuest::LoadProgressChanged(content::WebContents* source,
610 double progress) { 495 double progress) {
611 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 496 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
612 args->SetString(guestview::kUrl, guest_web_contents()->GetURL().spec()); 497 args->SetString(guestview::kUrl, guest_web_contents()->GetURL().spec());
613 args->SetDouble(webview::kProgress, progress); 498 args->SetDouble(webview::kProgress, progress);
614 DispatchEvent( 499 DispatchEventToEmbedder(
615 new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass())); 500 new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass()));
616 } 501 }
617 502
618 void WebViewGuest::LoadAbort(bool is_top_level, 503 void WebViewGuest::LoadAbort(bool is_top_level,
619 const GURL& url, 504 const GURL& url,
620 const std::string& error_type) { 505 const std::string& error_type) {
621 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 506 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
622 args->SetBoolean(guestview::kIsTopLevel, is_top_level); 507 args->SetBoolean(guestview::kIsTopLevel, is_top_level);
623 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); 508 args->SetString(guestview::kUrl, url.possibly_invalid_spec());
624 args->SetString(guestview::kReason, error_type); 509 args->SetString(guestview::kReason, error_type);
625 DispatchEvent( 510 DispatchEventToEmbedder(
626 new GuestViewBase::Event(webview::kEventLoadAbort, args.Pass())); 511 new GuestViewBase::Event(webview::kEventLoadAbort, args.Pass()));
627 } 512 }
628 513
629 void WebViewGuest::OnUpdateFrameName(bool is_top_level, 514 void WebViewGuest::OnUpdateFrameName(bool is_top_level,
630 const std::string& name) { 515 const std::string& name) {
631 if (!is_top_level) 516 if (!is_top_level)
632 return; 517 return;
633 518
634 if (name_ == name) 519 if (name_ == name)
635 return; 520 return;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 params.user_gesture, 559 params.user_gesture,
675 new_guest->guest_web_contents()); 560 new_guest->guest_web_contents());
676 } 561 }
677 562
678 // TODO(fsamuel): Find a reliable way to test the 'responsive' and 563 // TODO(fsamuel): Find a reliable way to test the 'responsive' and
679 // 'unresponsive' events. 564 // 'unresponsive' events.
680 void WebViewGuest::RendererResponsive(content::WebContents* source) { 565 void WebViewGuest::RendererResponsive(content::WebContents* source) {
681 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 566 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
682 args->SetInteger(webview::kProcessId, 567 args->SetInteger(webview::kProcessId,
683 guest_web_contents()->GetRenderProcessHost()->GetID()); 568 guest_web_contents()->GetRenderProcessHost()->GetID());
684 DispatchEvent( 569 DispatchEventToEmbedder(
685 new GuestViewBase::Event(webview::kEventResponsive, args.Pass())); 570 new GuestViewBase::Event(webview::kEventResponsive, args.Pass()));
686 } 571 }
687 572
688 void WebViewGuest::RendererUnresponsive(content::WebContents* source) { 573 void WebViewGuest::RendererUnresponsive(content::WebContents* source) {
689 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 574 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
690 args->SetInteger(webview::kProcessId, 575 args->SetInteger(webview::kProcessId,
691 guest_web_contents()->GetRenderProcessHost()->GetID()); 576 guest_web_contents()->GetRenderProcessHost()->GetID());
692 DispatchEvent( 577 DispatchEventToEmbedder(
693 new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass())); 578 new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass()));
694 } 579 }
695 580
696 void WebViewGuest::Observe(int type, 581 void WebViewGuest::Observe(int type,
697 const content::NotificationSource& source, 582 const content::NotificationSource& source,
698 const content::NotificationDetails& details) { 583 const content::NotificationDetails& details) {
699 switch (type) { 584 switch (type) {
700 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { 585 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: {
701 DCHECK_EQ(content::Source<WebContents>(source).ptr(), 586 DCHECK_EQ(content::Source<WebContents>(source).ptr(),
702 guest_web_contents()); 587 guest_web_contents());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 guest_web_contents()->GetController().GoToOffset(relative_index); 627 guest_web_contents()->GetController().GoToOffset(relative_index);
743 } 628 }
744 629
745 void WebViewGuest::Reload() { 630 void WebViewGuest::Reload() {
746 // TODO(fsamuel): Don't check for repost because we don't want to show 631 // TODO(fsamuel): Don't check for repost because we don't want to show
747 // Chromium's repost warning. We might want to implement a separate API 632 // Chromium's repost warning. We might want to implement a separate API
748 // for registering a callback if a repost is about to happen. 633 // for registering a callback if a repost is about to happen.
749 guest_web_contents()->GetController().Reload(false); 634 guest_web_contents()->GetController().Reload(false);
750 } 635 }
751 636
752 void WebViewGuest::RequestFileSystemPermission(
753 const GURL& url,
754 bool allowed_by_default,
755 const base::Callback<void(bool)>& callback) {
756 base::DictionaryValue request_info;
757 request_info.Set(guestview::kUrl, base::Value::CreateStringValue(url.spec()));
758 RequestPermission(
759 WEB_VIEW_PERMISSION_TYPE_FILESYSTEM,
760 request_info,
761 base::Bind(&WebViewGuest::OnWebViewFileSystemPermissionResponse,
762 base::Unretained(this),
763 callback),
764 allowed_by_default);
765 }
766
767 void WebViewGuest::OnWebViewFileSystemPermissionResponse(
768 const base::Callback<void(bool)>& callback,
769 bool allow,
770 const std::string& user_input) {
771 callback.Run(allow && attached());
772 }
773
774 void WebViewGuest::RequestGeolocationPermission(
775 int bridge_id,
776 const GURL& requesting_frame,
777 bool user_gesture,
778 const base::Callback<void(bool)>& callback) {
779 base::DictionaryValue request_info;
780 request_info.Set(guestview::kUrl,
781 base::Value::CreateStringValue(requesting_frame.spec()));
782 request_info.Set(guestview::kUserGesture,
783 base::Value::CreateBooleanValue(user_gesture));
784
785 // It is safe to hold an unretained pointer to WebViewGuest because this
786 // callback is called from WebViewGuest::SetPermission.
787 const PermissionResponseCallback permission_callback =
788 base::Bind(&WebViewGuest::OnWebViewGeolocationPermissionResponse,
789 base::Unretained(this),
790 bridge_id,
791 user_gesture,
792 callback);
793 int request_id = RequestPermission(
794 WEB_VIEW_PERMISSION_TYPE_GEOLOCATION,
795 request_info,
796 permission_callback,
797 false /* allowed_by_default */);
798 bridge_id_to_request_id_map_[bridge_id] = request_id;
799 }
800
801 void WebViewGuest::OnWebViewGeolocationPermissionResponse(
802 int bridge_id,
803 bool user_gesture,
804 const base::Callback<void(bool)>& callback,
805 bool allow,
806 const std::string& user_input) {
807 // The <webview> embedder has allowed the permission. We now need to make sure
808 // that the embedder has geolocation permission.
809 RemoveBridgeID(bridge_id);
810
811 if (!allow || !attached()) {
812 callback.Run(false);
813 return;
814 }
815
816 Profile* profile = Profile::FromBrowserContext(browser_context());
817 GeolocationPermissionContextFactory::GetForProfile(profile)->
818 RequestGeolocationPermission(
819 embedder_web_contents(),
820 // The geolocation permission request here is not initiated
821 // through WebGeolocationPermissionRequest. We are only interested
822 // in the fact whether the embedder/app has geolocation
823 // permission. Therefore we use an invalid |bridge_id|.
824 -1,
825 embedder_web_contents()->GetLastCommittedURL(),
826 user_gesture,
827 callback,
828 NULL);
829 }
830
831 void WebViewGuest::CancelGeolocationPermissionRequest(int bridge_id) {
832 int request_id = RemoveBridgeID(bridge_id);
833 RequestMap::iterator request_itr =
834 pending_permission_requests_.find(request_id);
835
836 if (request_itr == pending_permission_requests_.end())
837 return;
838
839 pending_permission_requests_.erase(request_itr);
840 }
841
842 void WebViewGuest::OnWebViewMediaPermissionResponse(
843 const content::MediaStreamRequest& request,
844 const content::MediaResponseCallback& callback,
845 bool allow,
846 const std::string& user_input) {
847 if (!allow || !attached()) {
848 // Deny the request.
849 callback.Run(content::MediaStreamDevices(),
850 content::MEDIA_DEVICE_INVALID_STATE,
851 scoped_ptr<content::MediaStreamUI>());
852 return;
853 }
854 if (!embedder_web_contents()->GetDelegate())
855 return;
856
857 embedder_web_contents()->GetDelegate()->
858 RequestMediaAccessPermission(embedder_web_contents(), request, callback);
859 }
860
861 void WebViewGuest::OnWebViewDownloadPermissionResponse(
862 const base::Callback<void(bool)>& callback,
863 bool allow,
864 const std::string& user_input) {
865 callback.Run(allow && attached());
866 }
867
868 void WebViewGuest::OnWebViewPointerLockPermissionResponse(
869 const base::Callback<void(bool)>& callback,
870 bool allow,
871 const std::string& user_input) {
872 callback.Run(allow && attached());
873 }
874
875 WebViewGuest::SetPermissionResult WebViewGuest::SetPermission(
876 int request_id,
877 PermissionResponseAction action,
878 const std::string& user_input) {
879 RequestMap::iterator request_itr =
880 pending_permission_requests_.find(request_id);
881
882 if (request_itr == pending_permission_requests_.end())
883 return SET_PERMISSION_INVALID;
884
885 const PermissionResponseInfo& info = request_itr->second;
886 bool allow = (action == ALLOW) ||
887 ((action == DEFAULT) && info.allowed_by_default);
888
889 info.callback.Run(allow, user_input);
890
891 // Only record user initiated (i.e. non-default) actions.
892 if (action != DEFAULT)
893 RecordUserInitiatedUMA(info, allow);
894
895 pending_permission_requests_.erase(request_itr);
896
897 return allow ? SET_PERMISSION_ALLOWED : SET_PERMISSION_DENIED;
898 }
899
900 void WebViewGuest::SetUserAgentOverride( 637 void WebViewGuest::SetUserAgentOverride(
901 const std::string& user_agent_override) { 638 const std::string& user_agent_override) {
902 if (!attached()) 639 if (!attached())
903 return; 640 return;
904 is_overriding_user_agent_ = !user_agent_override.empty(); 641 is_overriding_user_agent_ = !user_agent_override.empty();
905 if (is_overriding_user_agent_) { 642 if (is_overriding_user_agent_) {
906 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA")); 643 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA"));
907 } 644 }
908 guest_web_contents()->SetUserAgentOverride(user_agent_override); 645 guest_web_contents()->SetUserAgentOverride(user_agent_override);
909 } 646 }
(...skipping 26 matching lines...) Expand all
936 removal_mask, 673 removal_mask,
937 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, 674 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
938 GURL(), 675 GURL(),
939 content::StoragePartition::OriginMatcherFunction(), 676 content::StoragePartition::OriginMatcherFunction(),
940 remove_since, 677 remove_since,
941 base::Time::Now(), 678 base::Time::Now(),
942 callback); 679 callback);
943 return true; 680 return true;
944 } 681 }
945 682
946 // static
947 void WebViewGuest::FileSystemAccessedAsync(int render_process_id,
948 int render_frame_id,
949 int request_id,
950 const GURL& url,
951 bool blocked_by_policy) {
952 WebViewGuest* guest =
953 WebViewGuest::FromFrameID(render_process_id, render_frame_id);
954 DCHECK(guest);
955 guest->RequestFileSystemPermission(
956 url,
957 !blocked_by_policy,
958 base::Bind(&WebViewGuest::FileSystemAccessedAsyncResponse,
959 render_process_id,
960 render_frame_id,
961 request_id,
962 url));
963 }
964
965 // static
966 void WebViewGuest::FileSystemAccessedAsyncResponse(int render_process_id,
967 int render_frame_id,
968 int request_id,
969 const GURL& url,
970 bool allowed) {
971 TabSpecificContentSettings::FileSystemAccessed(
972 render_process_id, render_frame_id, url, !allowed);
973 content::RenderFrameHost* render_frame_host =
974 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
975 if (!render_frame_host)
976 return;
977 render_frame_host->Send(
978 new ChromeViewMsg_RequestFileSystemAccessAsyncResponse(
979 render_frame_id, request_id, allowed));
980 }
981
982 // static
983 void WebViewGuest::FileSystemAccessedSync(int render_process_id,
984 int render_frame_id,
985 const GURL& url,
986 bool blocked_by_policy,
987 IPC::Message* reply_msg) {
988 WebViewGuest* guest =
989 WebViewGuest::FromFrameID(render_process_id, render_frame_id);
990 DCHECK(guest);
991 guest->RequestFileSystemPermission(
992 url,
993 !blocked_by_policy,
994 base::Bind(&WebViewGuest::FileSystemAccessedSyncResponse,
995 render_process_id,
996 render_frame_id,
997 url,
998 reply_msg));
999 }
1000
1001 // static
1002 void WebViewGuest::FileSystemAccessedSyncResponse(int render_process_id,
1003 int render_frame_id,
1004 const GURL& url,
1005 IPC::Message* reply_msg,
1006 bool allowed) {
1007 TabSpecificContentSettings::FileSystemAccessed(
1008 render_process_id, render_frame_id, url, !allowed);
1009 ChromeViewHostMsg_RequestFileSystemAccessSync::WriteReplyParams(reply_msg,
1010 allowed);
1011 content::RenderFrameHost* render_frame_host =
1012 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
1013 if (!render_frame_id)
1014 return;
1015 render_frame_host->Send(reply_msg);
1016 }
1017
1018 WebViewGuest::~WebViewGuest() { 683 WebViewGuest::~WebViewGuest() {
1019 } 684 }
1020 685
1021 void WebViewGuest::DidCommitProvisionalLoadForFrame( 686 void WebViewGuest::DidCommitProvisionalLoadForFrame(
1022 content::RenderFrameHost* render_frame_host, 687 content::RenderFrameHost* render_frame_host,
1023 const GURL& url, 688 const GURL& url,
1024 content::PageTransition transition_type) { 689 content::PageTransition transition_type) {
1025 find_helper_.CancelAllFindSessions(); 690 find_helper_.CancelAllFindSessions();
1026 691
1027 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 692 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1028 args->SetString(guestview::kUrl, url.spec()); 693 args->SetString(guestview::kUrl, url.spec());
1029 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); 694 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent());
1030 args->SetInteger(webview::kInternalCurrentEntryIndex, 695 args->SetInteger(webview::kInternalCurrentEntryIndex,
1031 guest_web_contents()->GetController().GetCurrentEntryIndex()); 696 guest_web_contents()->GetController().GetCurrentEntryIndex());
1032 args->SetInteger(webview::kInternalEntryCount, 697 args->SetInteger(webview::kInternalEntryCount,
1033 guest_web_contents()->GetController().GetEntryCount()); 698 guest_web_contents()->GetController().GetEntryCount());
1034 args->SetInteger(webview::kInternalProcessId, 699 args->SetInteger(webview::kInternalProcessId,
1035 guest_web_contents()->GetRenderProcessHost()->GetID()); 700 guest_web_contents()->GetRenderProcessHost()->GetID());
1036 DispatchEvent( 701 DispatchEventToEmbedder(
1037 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); 702 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass()));
1038 703
1039 // Update the current zoom factor for the new page. 704 // Update the current zoom factor for the new page.
1040 ZoomController* zoom_controller = 705 ZoomController* zoom_controller =
1041 ZoomController::FromWebContents(guest_web_contents()); 706 ZoomController::FromWebContents(guest_web_contents());
1042 DCHECK(zoom_controller); 707 DCHECK(zoom_controller);
1043 current_zoom_factor_ = zoom_controller->GetZoomLevel(); 708 current_zoom_factor_ = zoom_controller->GetZoomLevel();
1044 709
1045 if (!render_frame_host->GetParent()) { 710 if (!render_frame_host->GetParent()) {
1046 chromevox_injected_ = false; 711 chromevox_injected_ = false;
(...skipping 14 matching lines...) Expand all
1061 } 726 }
1062 727
1063 void WebViewGuest::DidStartProvisionalLoadForFrame( 728 void WebViewGuest::DidStartProvisionalLoadForFrame(
1064 content::RenderFrameHost* render_frame_host, 729 content::RenderFrameHost* render_frame_host,
1065 const GURL& validated_url, 730 const GURL& validated_url,
1066 bool is_error_page, 731 bool is_error_page,
1067 bool is_iframe_srcdoc) { 732 bool is_iframe_srcdoc) {
1068 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 733 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1069 args->SetString(guestview::kUrl, validated_url.spec()); 734 args->SetString(guestview::kUrl, validated_url.spec());
1070 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); 735 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent());
1071 DispatchEvent( 736 DispatchEventToEmbedder(
1072 new GuestViewBase::Event(webview::kEventLoadStart, args.Pass())); 737 new GuestViewBase::Event(webview::kEventLoadStart, args.Pass()));
1073 } 738 }
1074 739
1075 void WebViewGuest::DocumentLoadedInFrame( 740 void WebViewGuest::DocumentLoadedInFrame(
1076 int64 frame_id, 741 int64 frame_id,
1077 content::RenderViewHost* render_view_host) { 742 content::RenderViewHost* render_view_host) {
1078 if (frame_id == main_frame_id_) 743 if (frame_id == main_frame_id_)
1079 InjectChromeVoxIfNeeded(render_view_host); 744 InjectChromeVoxIfNeeded(render_view_host);
1080 } 745 }
1081 746
1082 bool WebViewGuest::OnMessageReceived(const IPC::Message& message, 747 bool WebViewGuest::OnMessageReceived(const IPC::Message& message,
1083 RenderFrameHost* render_frame_host) { 748 RenderFrameHost* render_frame_host) {
1084 bool handled = true; 749 bool handled = true;
1085 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) 750 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message)
1086 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdateFrameName, OnUpdateFrameName) 751 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdateFrameName, OnUpdateFrameName)
1087 IPC_MESSAGE_UNHANDLED(handled = false) 752 IPC_MESSAGE_UNHANDLED(handled = false)
1088 IPC_END_MESSAGE_MAP() 753 IPC_END_MESSAGE_MAP()
1089 return handled; 754 return handled;
1090 } 755 }
1091 756
1092 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { 757 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) {
1093 // Cancel all find sessions in progress. 758 // Cancel all find sessions in progress.
1094 find_helper_.CancelAllFindSessions(); 759 find_helper_.CancelAllFindSessions();
1095 760
1096 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 761 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1097 args->SetInteger(webview::kProcessId, 762 args->SetInteger(webview::kProcessId,
1098 guest_web_contents()->GetRenderProcessHost()->GetID()); 763 guest_web_contents()->GetRenderProcessHost()->GetID());
1099 args->SetString(webview::kReason, TerminationStatusToString(status)); 764 args->SetString(webview::kReason, TerminationStatusToString(status));
1100 DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass())); 765 DispatchEventToEmbedder(
766 new GuestViewBase::Event(webview::kEventExit, args.Pass()));
1101 } 767 }
1102 768
1103 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { 769 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) {
1104 if (!attached()) 770 if (!attached())
1105 return; 771 return;
1106 content::NavigationController& controller = 772 content::NavigationController& controller =
1107 guest_web_contents()->GetController(); 773 guest_web_contents()->GetController();
1108 content::NavigationEntry* entry = controller.GetVisibleEntry(); 774 content::NavigationEntry* entry = controller.GetVisibleEntry();
1109 if (!entry) 775 if (!entry)
1110 return; 776 return;
1111 entry->SetIsOverridingUserAgent(!user_agent.empty()); 777 entry->SetIsOverridingUserAgent(!user_agent.empty());
1112 guest_web_contents()->GetController().Reload(false); 778 guest_web_contents()->GetController().Reload(false);
1113 } 779 }
1114 780
1115 void WebViewGuest::RenderViewReady() { 781 void WebViewGuest::RenderViewReady() {
1116 // The guest RenderView should always live in an isolated guest process. 782 // The guest RenderView should always live in an isolated guest process.
1117 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); 783 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest());
1118 Send(new ChromeViewMsg_SetName(guest_web_contents()->GetRoutingID(), name_)); 784 Send(new ChromeViewMsg_SetName(guest_web_contents()->GetRoutingID(), name_));
1119 } 785 }
1120 786
1121 void WebViewGuest::ReportFrameNameChange(const std::string& name) { 787 void WebViewGuest::ReportFrameNameChange(const std::string& name) {
1122 name_ = name; 788 name_ = name;
1123 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 789 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1124 args->SetString(webview::kName, name); 790 args->SetString(webview::kName, name);
1125 DispatchEvent( 791 DispatchEventToEmbedder(
1126 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); 792 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass()));
1127 } 793 }
1128 794
1129 void WebViewGuest::LoadHandlerCalled() { 795 void WebViewGuest::LoadHandlerCalled() {
1130 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 796 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1131 DispatchEvent( 797 DispatchEventToEmbedder(
1132 new GuestViewBase::Event(webview::kEventContentLoad, args.Pass())); 798 new GuestViewBase::Event(webview::kEventContentLoad, args.Pass()));
1133 } 799 }
1134 800
1135 void WebViewGuest::LoadRedirect(const GURL& old_url, 801 void WebViewGuest::LoadRedirect(const GURL& old_url,
1136 const GURL& new_url, 802 const GURL& new_url,
1137 bool is_top_level) { 803 bool is_top_level) {
1138 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 804 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1139 args->SetBoolean(guestview::kIsTopLevel, is_top_level); 805 args->SetBoolean(guestview::kIsTopLevel, is_top_level);
1140 args->SetString(webview::kNewURL, new_url.spec()); 806 args->SetString(webview::kNewURL, new_url.spec());
1141 args->SetString(webview::kOldURL, old_url.spec()); 807 args->SetString(webview::kOldURL, old_url.spec());
1142 DispatchEvent( 808 DispatchEventToEmbedder(
1143 new GuestViewBase::Event(webview::kEventLoadRedirect, args.Pass())); 809 new GuestViewBase::Event(webview::kEventLoadRedirect, args.Pass()));
1144 } 810 }
1145 811
1146 void WebViewGuest::PushWebViewStateToIOThread() { 812 void WebViewGuest::PushWebViewStateToIOThread() {
1147 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); 813 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL();
1148 std::string partition_domain; 814 std::string partition_domain;
1149 std::string partition_id; 815 std::string partition_id;
1150 bool in_memory; 816 bool in_memory;
1151 if (!GetGuestPartitionConfigForSite( 817 if (!GetGuestPartitionConfigForSite(
1152 site_url, &partition_domain, &partition_id, &in_memory)) { 818 site_url, &partition_domain, &partition_id, &in_memory)) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 create_params); 860 create_params);
1195 } 861 }
1196 862
1197 void WebViewGuest::SizeChanged(const gfx::Size& old_size, 863 void WebViewGuest::SizeChanged(const gfx::Size& old_size,
1198 const gfx::Size& new_size) { 864 const gfx::Size& new_size) {
1199 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 865 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1200 args->SetInteger(webview::kOldHeight, old_size.height()); 866 args->SetInteger(webview::kOldHeight, old_size.height());
1201 args->SetInteger(webview::kOldWidth, old_size.width()); 867 args->SetInteger(webview::kOldWidth, old_size.width());
1202 args->SetInteger(webview::kNewHeight, new_size.height()); 868 args->SetInteger(webview::kNewHeight, new_size.height());
1203 args->SetInteger(webview::kNewWidth, new_size.width()); 869 args->SetInteger(webview::kNewWidth, new_size.width());
1204 DispatchEvent( 870 DispatchEventToEmbedder(
1205 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); 871 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass()));
1206 } 872 }
1207 873
1208 void WebViewGuest::RequestMediaAccessPermission( 874 void WebViewGuest::RequestMediaAccessPermission(
1209 content::WebContents* source, 875 content::WebContents* source,
1210 const content::MediaStreamRequest& request, 876 const content::MediaStreamRequest& request,
1211 const content::MediaResponseCallback& callback) { 877 const content::MediaResponseCallback& callback) {
1212 base::DictionaryValue request_info; 878 web_view_permission_helper_->RequestMediaAccessPermission(source,
1213 request_info.Set( 879 request,
1214 guestview::kUrl, 880 callback);
1215 base::Value::CreateStringValue(request.security_origin.spec()));
1216 RequestPermission(WEB_VIEW_PERMISSION_TYPE_MEDIA,
1217 request_info,
1218 base::Bind(&WebViewGuest::OnWebViewMediaPermissionResponse,
1219 base::Unretained(this),
1220 request,
1221 callback),
1222 false /* allowed_by_default */);
1223 } 881 }
1224 882
1225 void WebViewGuest::CanDownload( 883 void WebViewGuest::CanDownload(
1226 content::RenderViewHost* render_view_host, 884 content::RenderViewHost* render_view_host,
1227 const GURL& url, 885 const GURL& url,
1228 const std::string& request_method, 886 const std::string& request_method,
1229 const base::Callback<void(bool)>& callback) { 887 const base::Callback<void(bool)>& callback) {
1230 base::DictionaryValue request_info; 888 web_view_permission_helper_->CanDownload(render_view_host,
1231 request_info.Set( 889 url,
1232 guestview::kUrl, 890 request_method,
1233 base::Value::CreateStringValue(url.spec())); 891 callback);
1234 RequestPermission(
1235 WEB_VIEW_PERMISSION_TYPE_DOWNLOAD,
1236 request_info,
1237 base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse,
1238 base::Unretained(this),
1239 callback),
1240 false /* allowed_by_default */);
1241 } 892 }
1242 893
1243 void WebViewGuest::RequestPointerLockPermission( 894 void WebViewGuest::RequestPointerLockPermission(
1244 bool user_gesture, 895 bool user_gesture,
1245 bool last_unlocked_by_target, 896 bool last_unlocked_by_target,
1246 const base::Callback<void(bool)>& callback) { 897 const base::Callback<void(bool)>& callback) {
1247 base::DictionaryValue request_info; 898 web_view_permission_helper_->RequestPointerLockPermission(
1248 request_info.Set(guestview::kUserGesture, 899 user_gesture,
1249 base::Value::CreateBooleanValue(user_gesture)); 900 last_unlocked_by_target,
1250 request_info.Set(webview::kLastUnlockedBySelf, 901 callback);
1251 base::Value::CreateBooleanValue(last_unlocked_by_target));
1252 request_info.Set(guestview::kUrl,
1253 base::Value::CreateStringValue(
1254 guest_web_contents()->GetLastCommittedURL().spec()));
1255
1256 RequestPermission(
1257 WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK,
1258 request_info,
1259 base::Bind(&WebViewGuest::OnWebViewPointerLockPermissionResponse,
1260 base::Unretained(this),
1261 callback),
1262 false /* allowed_by_default */);
1263 } 902 }
1264 903
1265 void WebViewGuest::WillAttachToEmbedder() { 904 void WebViewGuest::WillAttachToEmbedder() {
1266 // We must install the mapping from guests to WebViews prior to resuming 905 // We must install the mapping from guests to WebViews prior to resuming
1267 // suspended resource loads so that the WebRequest API will catch resource 906 // suspended resource loads so that the WebRequest API will catch resource
1268 // requests. 907 // requests.
1269 PushWebViewStateToIOThread(); 908 PushWebViewStateToIOThread();
1270 } 909 }
1271 910
1272 content::JavaScriptDialogManager* 911 content::JavaScriptDialogManager*
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 chromeos::AccessibilityManager* manager = 985 chromeos::AccessibilityManager* manager =
1347 chromeos::AccessibilityManager::Get(); 986 chromeos::AccessibilityManager::Get();
1348 if (manager && manager->IsSpokenFeedbackEnabled()) { 987 if (manager && manager->IsSpokenFeedbackEnabled()) {
1349 manager->InjectChromeVox(render_view_host); 988 manager->InjectChromeVox(render_view_host);
1350 chromevox_injected_ = true; 989 chromevox_injected_ = true;
1351 } 990 }
1352 } 991 }
1353 #endif 992 #endif
1354 } 993 }
1355 994
1356 int WebViewGuest::RemoveBridgeID(int bridge_id) {
1357 std::map<int, int>::iterator bridge_itr =
1358 bridge_id_to_request_id_map_.find(bridge_id);
1359 if (bridge_itr == bridge_id_to_request_id_map_.end())
1360 return webview::kInvalidPermissionRequestID;
1361
1362 int request_id = bridge_itr->second;
1363 bridge_id_to_request_id_map_.erase(bridge_itr);
1364 return request_id;
1365 }
1366
1367 int WebViewGuest::RequestPermission(
1368 WebViewPermissionType permission_type,
1369 const base::DictionaryValue& request_info,
1370 const PermissionResponseCallback& callback,
1371 bool allowed_by_default) {
1372 // If there are too many pending permission requests then reject this request.
1373 if (pending_permission_requests_.size() >=
1374 webview::kMaxOutstandingPermissionRequests) {
1375 // Let the stack unwind before we deny the permission request so that
1376 // objects held by the permission request are not destroyed immediately
1377 // after creation. This is to allow those same objects to be accessed again
1378 // in the same scope without fear of use after freeing.
1379 base::MessageLoop::current()->PostTask(
1380 FROM_HERE,
1381 base::Bind(&PermissionResponseCallback::Run,
1382 base::Owned(new PermissionResponseCallback(callback)),
1383 allowed_by_default,
1384 std::string()));
1385 return webview::kInvalidPermissionRequestID;
1386 }
1387
1388 int request_id = next_permission_request_id_++;
1389 pending_permission_requests_[request_id] =
1390 PermissionResponseInfo(callback, permission_type, allowed_by_default);
1391 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy());
1392 args->SetInteger(webview::kRequestId, request_id);
1393 switch (permission_type) {
1394 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: {
1395 DispatchEvent(
1396 new GuestViewBase::Event(webview::kEventNewWindow, args.Pass()));
1397 break;
1398 }
1399 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: {
1400 DispatchEvent(
1401 new GuestViewBase::Event(webview::kEventDialog, args.Pass()));
1402 break;
1403 }
1404 default: {
1405 args->SetString(webview::kPermission,
1406 PermissionTypeToString(permission_type));
1407 DispatchEvent(new GuestViewBase::Event(webview::kEventPermissionRequest,
1408 args.Pass()));
1409 break;
1410 }
1411 }
1412 return request_id;
1413 }
1414
1415 bool WebViewGuest::HandleKeyboardShortcuts( 995 bool WebViewGuest::HandleKeyboardShortcuts(
1416 const content::NativeWebKeyboardEvent& event) { 996 const content::NativeWebKeyboardEvent& event) {
1417 if (event.type != blink::WebInputEvent::RawKeyDown) 997 if (event.type != blink::WebInputEvent::RawKeyDown)
1418 return false; 998 return false;
1419 999
1420 // If the user hits the escape key without any modifiers then unlock the 1000 // If the user hits the escape key without any modifiers then unlock the
1421 // mouse if necessary. 1001 // mouse if necessary.
1422 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) && 1002 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) &&
1423 !(event.modifiers & blink::WebInputEvent::InputModifiers)) { 1003 !(event.modifiers & blink::WebInputEvent::InputModifiers)) {
1424 return guest_web_contents()->GotResponseToLockMouseRequest(false); 1004 return guest_web_contents()->GotResponseToLockMouseRequest(false);
(...skipping 20 matching lines...) Expand all
1445 1025
1446 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) { 1026 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) {
1447 Go(1); 1027 Go(1);
1448 return true; 1028 return true;
1449 } 1029 }
1450 #endif 1030 #endif
1451 1031
1452 return false; 1032 return false;
1453 } 1033 }
1454 1034
1455 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo()
1456 : permission_type(WEB_VIEW_PERMISSION_TYPE_UNKNOWN),
1457 allowed_by_default(false) {
1458 }
1459
1460 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo(
1461 const PermissionResponseCallback& callback,
1462 WebViewPermissionType permission_type,
1463 bool allowed_by_default)
1464 : callback(callback),
1465 permission_type(permission_type),
1466 allowed_by_default(allowed_by_default) {
1467 }
1468
1469 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() {
1470 }
1471
1472 void WebViewGuest::ShowContextMenu(int request_id, 1035 void WebViewGuest::ShowContextMenu(int request_id,
1473 const MenuItemVector* items) { 1036 const MenuItemVector* items) {
1474 if (!pending_menu_.get()) 1037 if (!pending_menu_.get())
1475 return; 1038 return;
1476 1039
1477 // Make sure this was the correct request. 1040 // Make sure this was the correct request.
1478 if (request_id != pending_context_menu_request_id_) 1041 if (request_id != pending_context_menu_request_id_)
1479 return; 1042 return;
1480 1043
1481 // TODO(lazyboy): Implement. 1044 // TODO(lazyboy): Implement.
(...skipping 15 matching lines...) Expand all
1497 void WebViewGuest::SetZoom(double zoom_factor) { 1060 void WebViewGuest::SetZoom(double zoom_factor) {
1498 ZoomController* zoom_controller = 1061 ZoomController* zoom_controller =
1499 ZoomController::FromWebContents(guest_web_contents()); 1062 ZoomController::FromWebContents(guest_web_contents());
1500 DCHECK(zoom_controller); 1063 DCHECK(zoom_controller);
1501 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); 1064 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor);
1502 zoom_controller->SetZoomLevel(zoom_level); 1065 zoom_controller->SetZoomLevel(zoom_level);
1503 1066
1504 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 1067 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1505 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); 1068 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_);
1506 args->SetDouble(webview::kNewZoomFactor, zoom_factor); 1069 args->SetDouble(webview::kNewZoomFactor, zoom_factor);
1507 DispatchEvent( 1070 DispatchEventToEmbedder(
1508 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass())); 1071 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass()));
1509 1072
1510 current_zoom_factor_ = zoom_factor; 1073 current_zoom_factor_ = zoom_factor;
1511 } 1074 }
1512 1075
1513 void WebViewGuest::AddNewContents(content::WebContents* source, 1076 void WebViewGuest::AddNewContents(content::WebContents* source,
1514 content::WebContents* new_contents, 1077 content::WebContents* new_contents,
1515 WindowOpenDisposition disposition, 1078 WindowOpenDisposition disposition,
1516 const gfx::Rect& initial_pos, 1079 const gfx::Rect& initial_pos,
1517 bool user_gesture, 1080 bool user_gesture,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 base::Value::CreateIntegerValue( 1176 base::Value::CreateIntegerValue(
1614 guest->GetGuestInstanceID())); 1177 guest->GetGuestInstanceID()));
1615 // We pass in partition info so that window-s created through newwindow 1178 // We pass in partition info so that window-s created through newwindow
1616 // API can use it to set their partition attribute. 1179 // API can use it to set their partition attribute.
1617 request_info.Set(webview::kStoragePartitionId, 1180 request_info.Set(webview::kStoragePartitionId,
1618 base::Value::CreateStringValue(storage_partition_id)); 1181 base::Value::CreateStringValue(storage_partition_id));
1619 request_info.Set(webview::kWindowOpenDisposition, 1182 request_info.Set(webview::kWindowOpenDisposition,
1620 base::Value::CreateStringValue( 1183 base::Value::CreateStringValue(
1621 WindowOpenDispositionToString(disposition))); 1184 WindowOpenDispositionToString(disposition)));
1622 1185
1623 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, 1186 web_view_permission_helper_->
1624 request_info, 1187 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW,
1625 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, 1188 request_info,
1626 base::Unretained(this), 1189 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse,
1627 guest->GetGuestInstanceID()), 1190 base::Unretained(this),
1628 false /* allowed_by_default */); 1191 guest->GetGuestInstanceID()),
1192 false /* allowed_by_default */);
1629 } 1193 }
1630 1194
1631 void WebViewGuest::DestroyUnattachedWindows() { 1195 void WebViewGuest::DestroyUnattachedWindows() {
1632 // Destroy() reaches in and removes the WebViewGuest from its opener's 1196 // Destroy() reaches in and removes the WebViewGuest from its opener's
1633 // pending_new_windows_ set. To avoid mutating the set while iterating, we 1197 // pending_new_windows_ set. To avoid mutating the set while iterating, we
1634 // create a copy of the pending new windows set and iterate over the copy. 1198 // create a copy of the pending new windows set and iterate over the copy.
1635 PendingWindowMap pending_new_windows(pending_new_windows_); 1199 PendingWindowMap pending_new_windows(pending_new_windows_);
1636 // Clean up unattached new windows opened by this guest. 1200 // Clean up unattached new windows opened by this guest.
1637 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); 1201 for (PendingWindowMap::const_iterator it = pending_new_windows.begin();
1638 it != pending_new_windows.end(); ++it) { 1202 it != pending_new_windows.end(); ++it) {
(...skipping 21 matching lines...) Expand all
1660 bool allow, 1224 bool allow,
1661 const std::string& user_input) { 1225 const std::string& user_input) {
1662 WebViewGuest* guest = 1226 WebViewGuest* guest =
1663 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1227 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1664 if (!guest) 1228 if (!guest)
1665 return; 1229 return;
1666 1230
1667 if (!allow) 1231 if (!allow)
1668 guest->Destroy(); 1232 guest->Destroy();
1669 } 1233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698