| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/guestview/webview/webview_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 "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 10 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 11 #include "chrome/browser/extensions/api/webview/webview_api.h" | 11 #include "chrome/browser/extensions/api/webview/webview_api.h" |
| 12 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 12 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
| 13 #include "chrome/browser/extensions/extension_renderer_state.h" | 13 #include "chrome/browser/extensions/extension_renderer_state.h" |
| 14 #include "chrome/browser/extensions/menu_manager.h" | 14 #include "chrome/browser/extensions/menu_manager.h" |
| 15 #include "chrome/browser/extensions/script_executor.h" | 15 #include "chrome/browser/extensions/script_executor.h" |
| 16 #include "chrome/browser/favicon/favicon_tab_helper.h" | 16 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 17 #include "chrome/browser/guest_view/guest_view_constants.h" | 17 #include "chrome/browser/guestview/guestview_constants.h" |
| 18 #include "chrome/browser/guest_view/web_view/web_view_constants.h" | 18 #include "chrome/browser/guestview/webview/webview_constants.h" |
| 19 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" | 19 #include "chrome/browser/guestview/webview/webview_permission_types.h" |
| 20 #include "chrome/common/chrome_version_info.h" | 20 #include "chrome/common/chrome_version_info.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/geolocation_permission_context.h" | 22 #include "content/public/browser/geolocation_permission_context.h" |
| 23 #include "content/public/browser/native_web_keyboard_event.h" | 23 #include "content/public/browser/native_web_keyboard_event.h" |
| 24 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
| 25 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
| 26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
| 28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
| 29 #include "content/public/browser/render_process_host.h" | 29 #include "content/public/browser/render_process_host.h" |
| 30 #include "content/public/browser/resource_request_details.h" | 30 #include "content/public/browser/resource_request_details.h" |
| 31 #include "content/public/browser/site_instance.h" | 31 #include "content/public/browser/site_instance.h" |
| 32 #include "content/public/browser/storage_partition.h" | 32 #include "content/public/browser/storage_partition.h" |
| 33 #include "content/public/browser/user_metrics.h" | 33 #include "content/public/browser/user_metrics.h" |
| 34 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 35 #include "content/public/browser/web_contents_delegate.h" | 35 #include "content/public/browser/web_contents_delegate.h" |
| 36 #include "content/public/common/media_stream_request.h" | 36 #include "content/public/common/media_stream_request.h" |
| 37 #include "content/public/common/page_zoom.h" | 37 #include "content/public/common/page_zoom.h" |
| 38 #include "content/public/common/result_codes.h" | 38 #include "content/public/common/result_codes.h" |
| 39 #include "content/public/common/stop_find_action.h" | 39 #include "content/public/common/stop_find_action.h" |
| 40 #include "extensions/common/constants.h" | 40 #include "extensions/common/constants.h" |
| 41 #include "net/base/net_errors.h" | 41 #include "net/base/net_errors.h" |
| 42 #include "third_party/WebKit/public/web/WebFindOptions.h" | 42 #include "third_party/WebKit/public/web/WebFindOptions.h" |
| 43 | 43 |
| 44 #if defined(ENABLE_PLUGINS) | 44 #if defined(ENABLE_PLUGINS) |
| 45 #include "chrome/browser/guest_view/web_view/plugin_permission_helper.h" | 45 #include "chrome/browser/guestview/webview/plugin_permission_helper.h" |
| 46 #endif | 46 #endif |
| 47 | 47 |
| 48 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
| 49 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 49 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 50 #endif | 50 #endif |
| 51 | 51 |
| 52 using base::UserMetricsAction; | 52 using base::UserMetricsAction; |
| 53 using content::WebContents; | 53 using content::WebContents; |
| 54 | 54 |
| 55 namespace { | 55 namespace { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 contents); | 123 contents); |
| 124 #if defined(ENABLE_PLUGINS) | 124 #if defined(ENABLE_PLUGINS) |
| 125 PluginPermissionHelper::CreateForWebContents(contents); | 125 PluginPermissionHelper::CreateForWebContents(contents); |
| 126 #endif | 126 #endif |
| 127 } | 127 } |
| 128 | 128 |
| 129 } // namespace | 129 } // namespace |
| 130 | 130 |
| 131 WebViewGuest::WebViewGuest(WebContents* guest_web_contents, | 131 WebViewGuest::WebViewGuest(WebContents* guest_web_contents, |
| 132 const std::string& extension_id) | 132 const std::string& extension_id) |
| 133 : GuestView<WebViewGuest>(guest_web_contents, extension_id), | 133 : GuestView(guest_web_contents, extension_id), |
| 134 WebContentsObserver(guest_web_contents), | 134 WebContentsObserver(guest_web_contents), |
| 135 script_executor_(new extensions::ScriptExecutor(guest_web_contents, | 135 script_executor_(new extensions::ScriptExecutor(guest_web_contents, |
| 136 &script_observers_)), | 136 &script_observers_)), |
| 137 next_permission_request_id_(0), | 137 next_permission_request_id_(0), |
| 138 is_overriding_user_agent_(false), | 138 is_overriding_user_agent_(false), |
| 139 pending_reload_on_attachment_(false), | 139 pending_reload_on_attachment_(false), |
| 140 main_frame_id_(0), | 140 main_frame_id_(0), |
| 141 chromevox_injected_(false), | 141 chromevox_injected_(false), |
| 142 find_helper_(this), | 142 find_helper_(this), |
| 143 javascript_dialog_helper_(this) { | 143 javascript_dialog_helper_(this) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 155 CHECK(accessibility_manager); | 155 CHECK(accessibility_manager); |
| 156 accessibility_subscription_ = accessibility_manager->RegisterCallback( | 156 accessibility_subscription_ = accessibility_manager->RegisterCallback( |
| 157 base::Bind(&WebViewGuest::OnAccessibilityStatusChanged, | 157 base::Bind(&WebViewGuest::OnAccessibilityStatusChanged, |
| 158 base::Unretained(this))); | 158 base::Unretained(this))); |
| 159 #endif | 159 #endif |
| 160 | 160 |
| 161 AttachWebViewHelpers(guest_web_contents); | 161 AttachWebViewHelpers(guest_web_contents); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // static | 164 // static |
| 165 const std::string& WebViewGuest::Type = "webview"; | 165 WebViewGuest* WebViewGuest::From(int embedder_process_id, |
| 166 int guest_instance_id) { |
| 167 GuestView* guest = GuestView::From(embedder_process_id, guest_instance_id); |
| 168 if (!guest) |
| 169 return NULL; |
| 170 return guest->AsWebView(); |
| 171 } |
| 172 |
| 173 // static |
| 174 WebViewGuest* WebViewGuest::FromWebContents(WebContents* contents) { |
| 175 GuestView* guest = GuestView::FromWebContents(contents); |
| 176 return guest ? guest->AsWebView() : NULL; |
| 177 } |
| 166 | 178 |
| 167 // static. | 179 // static. |
| 168 int WebViewGuest::GetViewInstanceId(WebContents* contents) { | 180 int WebViewGuest::GetViewInstanceId(WebContents* contents) { |
| 169 WebViewGuest* guest = FromWebContents(contents); | 181 WebViewGuest* guest = FromWebContents(contents); |
| 170 if (!guest) | 182 if (!guest) |
| 171 return guestview::kInstanceIDNone; | 183 return guestview::kInstanceIDNone; |
| 172 | 184 |
| 173 return guest->view_instance_id(); | 185 return guest->view_instance_id(); |
| 174 } | 186 } |
| 175 | 187 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 void WebViewGuest::Attach(WebContents* embedder_web_contents, | 278 void WebViewGuest::Attach(WebContents* embedder_web_contents, |
| 267 const base::DictionaryValue& args) { | 279 const base::DictionaryValue& args) { |
| 268 std::string user_agent_override; | 280 std::string user_agent_override; |
| 269 if (args.GetString(webview::kParameterUserAgentOverride, | 281 if (args.GetString(webview::kParameterUserAgentOverride, |
| 270 &user_agent_override)) { | 282 &user_agent_override)) { |
| 271 SetUserAgentOverride(user_agent_override); | 283 SetUserAgentOverride(user_agent_override); |
| 272 } else { | 284 } else { |
| 273 SetUserAgentOverride(""); | 285 SetUserAgentOverride(""); |
| 274 } | 286 } |
| 275 | 287 |
| 276 GuestViewBase::Attach(embedder_web_contents, args); | 288 GuestView::Attach(embedder_web_contents, args); |
| 277 | 289 |
| 278 AddWebViewToExtensionRendererState(); | 290 AddWebViewToExtensionRendererState(); |
| 279 } | 291 } |
| 280 | 292 |
| 293 GuestView::Type WebViewGuest::GetViewType() const { |
| 294 return GuestView::WEBVIEW; |
| 295 } |
| 296 |
| 297 WebViewGuest* WebViewGuest::AsWebView() { |
| 298 return this; |
| 299 } |
| 300 |
| 301 AdViewGuest* WebViewGuest::AsAdView() { |
| 302 return NULL; |
| 303 } |
| 304 |
| 281 void WebViewGuest::AddMessageToConsole(int32 level, | 305 void WebViewGuest::AddMessageToConsole(int32 level, |
| 282 const base::string16& message, | 306 const base::string16& message, |
| 283 int32 line_no, | 307 int32 line_no, |
| 284 const base::string16& source_id) { | 308 const base::string16& source_id) { |
| 285 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 309 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 286 // Log levels are from base/logging.h: LogSeverity. | 310 // Log levels are from base/logging.h: LogSeverity. |
| 287 args->SetInteger(webview::kLevel, level); | 311 args->SetInteger(webview::kLevel, level); |
| 288 args->SetString(webview::kMessage, message); | 312 args->SetString(webview::kMessage, message); |
| 289 args->SetInteger(webview::kLine, line_no); | 313 args->SetInteger(webview::kLine, line_no); |
| 290 args->SetString(webview::kSourceId, source_id); | 314 args->SetString(webview::kSourceId, source_id); |
| 291 DispatchEvent( | 315 DispatchEvent( |
| 292 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass())); | 316 new GuestView::Event(webview::kEventConsoleMessage, args.Pass())); |
| 293 } | 317 } |
| 294 | 318 |
| 295 void WebViewGuest::Close() { | 319 void WebViewGuest::Close() { |
| 296 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 320 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 297 DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass())); | 321 DispatchEvent(new GuestView::Event(webview::kEventClose, args.Pass())); |
| 298 } | 322 } |
| 299 | 323 |
| 300 void WebViewGuest::DidAttach() { | 324 void WebViewGuest::DidAttach() { |
| 301 if (pending_reload_on_attachment_) { | 325 if (pending_reload_on_attachment_) { |
| 302 pending_reload_on_attachment_ = false; | 326 pending_reload_on_attachment_ = false; |
| 303 guest_web_contents()->GetController().Reload(false); | 327 guest_web_contents()->GetController().Reload(false); |
| 304 } | 328 } |
| 305 } | 329 } |
| 306 | 330 |
| 307 void WebViewGuest::EmbedderDestroyed() { | 331 void WebViewGuest::EmbedderDestroyed() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 332 } | 356 } |
| 333 | 357 |
| 334 void WebViewGuest::GuestProcessGone(base::TerminationStatus status) { | 358 void WebViewGuest::GuestProcessGone(base::TerminationStatus status) { |
| 335 // Cancel all find sessions in progress. | 359 // Cancel all find sessions in progress. |
| 336 find_helper_.CancelAllFindSessions(); | 360 find_helper_.CancelAllFindSessions(); |
| 337 | 361 |
| 338 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 362 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 339 args->SetInteger(webview::kProcessId, | 363 args->SetInteger(webview::kProcessId, |
| 340 guest_web_contents()->GetRenderProcessHost()->GetID()); | 364 guest_web_contents()->GetRenderProcessHost()->GetID()); |
| 341 args->SetString(webview::kReason, TerminationStatusToString(status)); | 365 args->SetString(webview::kReason, TerminationStatusToString(status)); |
| 342 DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass())); | 366 DispatchEvent( |
| 367 new GuestView::Event(webview::kEventExit, args.Pass())); |
| 343 } | 368 } |
| 344 | 369 |
| 345 bool WebViewGuest::HandleKeyboardEvent( | 370 bool WebViewGuest::HandleKeyboardEvent( |
| 346 const content::NativeWebKeyboardEvent& event) { | 371 const content::NativeWebKeyboardEvent& event) { |
| 347 if (event.type != blink::WebInputEvent::RawKeyDown) | 372 if (event.type != blink::WebInputEvent::RawKeyDown) |
| 348 return false; | 373 return false; |
| 349 | 374 |
| 350 #if defined(OS_MACOSX) | 375 #if defined(OS_MACOSX) |
| 351 if (event.modifiers != blink::WebInputEvent::MetaKey) | 376 if (event.modifiers != blink::WebInputEvent::MetaKey) |
| 352 return false; | 377 return false; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 379 } | 404 } |
| 380 | 405 |
| 381 bool WebViewGuest::IsOverridingUserAgent() const { | 406 bool WebViewGuest::IsOverridingUserAgent() const { |
| 382 return is_overriding_user_agent_; | 407 return is_overriding_user_agent_; |
| 383 } | 408 } |
| 384 | 409 |
| 385 void WebViewGuest::LoadProgressed(double progress) { | 410 void WebViewGuest::LoadProgressed(double progress) { |
| 386 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 411 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 387 args->SetString(guestview::kUrl, guest_web_contents()->GetURL().spec()); | 412 args->SetString(guestview::kUrl, guest_web_contents()->GetURL().spec()); |
| 388 args->SetDouble(webview::kProgress, progress); | 413 args->SetDouble(webview::kProgress, progress); |
| 389 DispatchEvent( | 414 DispatchEvent(new GuestView::Event(webview::kEventLoadProgress, args.Pass())); |
| 390 new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass())); | |
| 391 } | 415 } |
| 392 | 416 |
| 393 void WebViewGuest::LoadAbort(bool is_top_level, | 417 void WebViewGuest::LoadAbort(bool is_top_level, |
| 394 const GURL& url, | 418 const GURL& url, |
| 395 const std::string& error_type) { | 419 const std::string& error_type) { |
| 396 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 420 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 397 args->SetBoolean(guestview::kIsTopLevel, is_top_level); | 421 args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
| 398 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); | 422 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); |
| 399 args->SetString(guestview::kReason, error_type); | 423 args->SetString(guestview::kReason, error_type); |
| 400 DispatchEvent( | 424 DispatchEvent(new GuestView::Event(webview::kEventLoadAbort, args.Pass())); |
| 401 new GuestViewBase::Event(webview::kEventLoadAbort, args.Pass())); | |
| 402 } | 425 } |
| 403 | 426 |
| 404 // TODO(fsamuel): Find a reliable way to test the 'responsive' and | 427 // TODO(fsamuel): Find a reliable way to test the 'responsive' and |
| 405 // 'unresponsive' events. | 428 // 'unresponsive' events. |
| 406 void WebViewGuest::RendererResponsive() { | 429 void WebViewGuest::RendererResponsive() { |
| 407 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 430 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 408 args->SetInteger(webview::kProcessId, | 431 args->SetInteger(webview::kProcessId, |
| 409 guest_web_contents()->GetRenderProcessHost()->GetID()); | 432 guest_web_contents()->GetRenderProcessHost()->GetID()); |
| 410 DispatchEvent( | 433 DispatchEvent(new GuestView::Event(webview::kEventResponsive, args.Pass())); |
| 411 new GuestViewBase::Event(webview::kEventResponsive, args.Pass())); | |
| 412 } | 434 } |
| 413 | 435 |
| 414 void WebViewGuest::RendererUnresponsive() { | 436 void WebViewGuest::RendererUnresponsive() { |
| 415 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 437 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 416 args->SetInteger(webview::kProcessId, | 438 args->SetInteger(webview::kProcessId, |
| 417 guest_web_contents()->GetRenderProcessHost()->GetID()); | 439 guest_web_contents()->GetRenderProcessHost()->GetID()); |
| 418 DispatchEvent( | 440 DispatchEvent(new GuestView::Event(webview::kEventUnresponsive, args.Pass())); |
| 419 new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass())); | |
| 420 } | 441 } |
| 421 | 442 |
| 422 void WebViewGuest::RequestPermission( | 443 void WebViewGuest::RequestPermission( |
| 423 BrowserPluginPermissionType permission_type, | 444 BrowserPluginPermissionType permission_type, |
| 424 const base::DictionaryValue& request_info, | 445 const base::DictionaryValue& request_info, |
| 425 const PermissionResponseCallback& callback, | 446 const PermissionResponseCallback& callback, |
| 426 bool allowed_by_default) { | 447 bool allowed_by_default) { |
| 427 RequestPermissionInternal(permission_type, | 448 RequestPermissionInternal(permission_type, |
| 428 request_info, | 449 request_info, |
| 429 callback, | 450 callback, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 459 } | 480 } |
| 460 } | 481 } |
| 461 | 482 |
| 462 void WebViewGuest::SetZoom(double zoom_factor) { | 483 void WebViewGuest::SetZoom(double zoom_factor) { |
| 463 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); | 484 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); |
| 464 guest_web_contents()->SetZoomLevel(zoom_level); | 485 guest_web_contents()->SetZoomLevel(zoom_level); |
| 465 | 486 |
| 466 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 487 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 467 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); | 488 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); |
| 468 args->SetDouble(webview::kNewZoomFactor, zoom_factor); | 489 args->SetDouble(webview::kNewZoomFactor, zoom_factor); |
| 469 DispatchEvent( | 490 DispatchEvent(new GuestView::Event(webview::kEventZoomChange, args.Pass())); |
| 470 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass())); | |
| 471 | 491 |
| 472 current_zoom_factor_ = zoom_factor; | 492 current_zoom_factor_ = zoom_factor; |
| 473 } | 493 } |
| 474 | 494 |
| 475 double WebViewGuest::GetZoom() { | 495 double WebViewGuest::GetZoom() { |
| 476 return current_zoom_factor_; | 496 return current_zoom_factor_; |
| 477 } | 497 } |
| 478 | 498 |
| 479 void WebViewGuest::Find( | 499 void WebViewGuest::Find( |
| 480 const base::string16& search_text, | 500 const base::string16& search_text, |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 | 707 |
| 688 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 708 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 689 args->SetString(guestview::kUrl, url.spec()); | 709 args->SetString(guestview::kUrl, url.spec()); |
| 690 args->SetBoolean(guestview::kIsTopLevel, is_main_frame); | 710 args->SetBoolean(guestview::kIsTopLevel, is_main_frame); |
| 691 args->SetInteger(webview::kInternalCurrentEntryIndex, | 711 args->SetInteger(webview::kInternalCurrentEntryIndex, |
| 692 guest_web_contents()->GetController().GetCurrentEntryIndex()); | 712 guest_web_contents()->GetController().GetCurrentEntryIndex()); |
| 693 args->SetInteger(webview::kInternalEntryCount, | 713 args->SetInteger(webview::kInternalEntryCount, |
| 694 guest_web_contents()->GetController().GetEntryCount()); | 714 guest_web_contents()->GetController().GetEntryCount()); |
| 695 args->SetInteger(webview::kInternalProcessId, | 715 args->SetInteger(webview::kInternalProcessId, |
| 696 guest_web_contents()->GetRenderProcessHost()->GetID()); | 716 guest_web_contents()->GetRenderProcessHost()->GetID()); |
| 697 DispatchEvent( | 717 DispatchEvent(new GuestView::Event(webview::kEventLoadCommit, args.Pass())); |
| 698 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); | |
| 699 | 718 |
| 700 // Update the current zoom factor for the new page. | 719 // Update the current zoom factor for the new page. |
| 701 current_zoom_factor_ = content::ZoomLevelToZoomFactor( | 720 current_zoom_factor_ = content::ZoomLevelToZoomFactor( |
| 702 guest_web_contents()->GetZoomLevel()); | 721 guest_web_contents()->GetZoomLevel()); |
| 703 | 722 |
| 704 if (is_main_frame) { | 723 if (is_main_frame) { |
| 705 chromevox_injected_ = false; | 724 chromevox_injected_ = false; |
| 706 main_frame_id_ = frame_id; | 725 main_frame_id_ = frame_id; |
| 707 } | 726 } |
| 708 } | 727 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 725 int64 frame_id, | 744 int64 frame_id, |
| 726 int64 parent_frame_id, | 745 int64 parent_frame_id, |
| 727 bool is_main_frame, | 746 bool is_main_frame, |
| 728 const GURL& validated_url, | 747 const GURL& validated_url, |
| 729 bool is_error_page, | 748 bool is_error_page, |
| 730 bool is_iframe_srcdoc, | 749 bool is_iframe_srcdoc, |
| 731 content::RenderViewHost* render_view_host) { | 750 content::RenderViewHost* render_view_host) { |
| 732 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 751 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 733 args->SetString(guestview::kUrl, validated_url.spec()); | 752 args->SetString(guestview::kUrl, validated_url.spec()); |
| 734 args->SetBoolean(guestview::kIsTopLevel, is_main_frame); | 753 args->SetBoolean(guestview::kIsTopLevel, is_main_frame); |
| 735 DispatchEvent( | 754 DispatchEvent(new GuestView::Event(webview::kEventLoadStart, args.Pass())); |
| 736 new GuestViewBase::Event(webview::kEventLoadStart, args.Pass())); | |
| 737 } | 755 } |
| 738 | 756 |
| 739 void WebViewGuest::DocumentLoadedInFrame( | 757 void WebViewGuest::DocumentLoadedInFrame( |
| 740 int64 frame_id, | 758 int64 frame_id, |
| 741 content::RenderViewHost* render_view_host) { | 759 content::RenderViewHost* render_view_host) { |
| 742 if (frame_id == main_frame_id_) | 760 if (frame_id == main_frame_id_) |
| 743 InjectChromeVoxIfNeeded(render_view_host); | 761 InjectChromeVoxIfNeeded(render_view_host); |
| 744 } | 762 } |
| 745 | 763 |
| 746 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { | 764 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { |
| 747 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 765 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 748 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); | 766 DispatchEvent(new GuestView::Event(webview::kEventLoadStop, args.Pass())); |
| 749 } | 767 } |
| 750 | 768 |
| 751 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { | 769 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { |
| 752 // Clean up custom context menu items for this guest. | 770 // Clean up custom context menu items for this guest. |
| 753 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( | 771 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( |
| 754 Profile::FromBrowserContext(browser_context())); | 772 Profile::FromBrowserContext(browser_context())); |
| 755 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey( | 773 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey( |
| 756 embedder_extension_id(), view_instance_id())); | 774 embedder_extension_id(), view_instance_id())); |
| 757 | 775 |
| 758 RemoveWebViewFromExtensionRendererState(web_contents); | 776 RemoveWebViewFromExtensionRendererState(web_contents); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 769 // We cannot reload now because all resource loads are suspended until | 787 // We cannot reload now because all resource loads are suspended until |
| 770 // attachment. | 788 // attachment. |
| 771 pending_reload_on_attachment_ = true; | 789 pending_reload_on_attachment_ = true; |
| 772 return; | 790 return; |
| 773 } | 791 } |
| 774 guest_web_contents()->GetController().Reload(false); | 792 guest_web_contents()->GetController().Reload(false); |
| 775 } | 793 } |
| 776 | 794 |
| 777 void WebViewGuest::LoadHandlerCalled() { | 795 void WebViewGuest::LoadHandlerCalled() { |
| 778 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 796 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 779 DispatchEvent( | 797 DispatchEvent(new GuestView::Event(webview::kEventContentLoad, args.Pass())); |
| 780 new GuestViewBase::Event(webview::kEventContentLoad, args.Pass())); | |
| 781 } | 798 } |
| 782 | 799 |
| 783 void WebViewGuest::LoadRedirect(const GURL& old_url, | 800 void WebViewGuest::LoadRedirect(const GURL& old_url, |
| 784 const GURL& new_url, | 801 const GURL& new_url, |
| 785 bool is_top_level) { | 802 bool is_top_level) { |
| 786 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 803 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 787 args->SetBoolean(guestview::kIsTopLevel, is_top_level); | 804 args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
| 788 args->SetString(webview::kNewURL, new_url.spec()); | 805 args->SetString(webview::kNewURL, new_url.spec()); |
| 789 args->SetString(webview::kOldURL, old_url.spec()); | 806 args->SetString(webview::kOldURL, old_url.spec()); |
| 790 DispatchEvent( | 807 DispatchEvent(new GuestView::Event(webview::kEventLoadRedirect, args.Pass())); |
| 791 new GuestViewBase::Event(webview::kEventLoadRedirect, args.Pass())); | |
| 792 } | 808 } |
| 793 | 809 |
| 794 void WebViewGuest::AddWebViewToExtensionRendererState() { | 810 void WebViewGuest::AddWebViewToExtensionRendererState() { |
| 795 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); | 811 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); |
| 796 std::string partition_domain; | 812 std::string partition_domain; |
| 797 std::string partition_id; | 813 std::string partition_id; |
| 798 bool in_memory; | 814 bool in_memory; |
| 799 if (!GetGuestPartitionConfigForSite( | 815 if (!GetGuestPartitionConfigForSite( |
| 800 site_url, &partition_domain, &partition_id, &in_memory)) { | 816 site_url, &partition_domain, &partition_id, &in_memory)) { |
| 801 NOTREACHED(); | 817 NOTREACHED(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 return default_url.Resolve(src); | 859 return default_url.Resolve(src); |
| 844 } | 860 } |
| 845 | 861 |
| 846 void WebViewGuest::SizeChanged(const gfx::Size& old_size, | 862 void WebViewGuest::SizeChanged(const gfx::Size& old_size, |
| 847 const gfx::Size& new_size) { | 863 const gfx::Size& new_size) { |
| 848 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 864 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 849 args->SetInteger(webview::kOldHeight, old_size.height()); | 865 args->SetInteger(webview::kOldHeight, old_size.height()); |
| 850 args->SetInteger(webview::kOldWidth, old_size.width()); | 866 args->SetInteger(webview::kOldWidth, old_size.width()); |
| 851 args->SetInteger(webview::kNewHeight, new_size.height()); | 867 args->SetInteger(webview::kNewHeight, new_size.height()); |
| 852 args->SetInteger(webview::kNewWidth, new_size.width()); | 868 args->SetInteger(webview::kNewWidth, new_size.width()); |
| 853 DispatchEvent( | 869 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); |
| 854 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); | |
| 855 } | 870 } |
| 856 | 871 |
| 857 void WebViewGuest::RequestMediaAccessPermission( | 872 void WebViewGuest::RequestMediaAccessPermission( |
| 858 const content::MediaStreamRequest& request, | 873 const content::MediaStreamRequest& request, |
| 859 const content::MediaResponseCallback& callback) { | 874 const content::MediaResponseCallback& callback) { |
| 860 base::DictionaryValue request_info; | 875 base::DictionaryValue request_info; |
| 861 request_info.Set( | 876 request_info.Set( |
| 862 guestview::kUrl, | 877 guestview::kUrl, |
| 863 base::Value::CreateStringValue(request.security_origin.spec())); | 878 base::Value::CreateStringValue(request.security_origin.spec())); |
| 864 RequestPermission(static_cast<BrowserPluginPermissionType>( | 879 RequestPermission(static_cast<BrowserPluginPermissionType>( |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 return webview::kInvalidPermissionRequestID; | 993 return webview::kInvalidPermissionRequestID; |
| 979 } | 994 } |
| 980 | 995 |
| 981 int request_id = next_permission_request_id_++; | 996 int request_id = next_permission_request_id_++; |
| 982 pending_permission_requests_[request_id] = | 997 pending_permission_requests_[request_id] = |
| 983 PermissionResponseInfo(callback, permission_type, allowed_by_default); | 998 PermissionResponseInfo(callback, permission_type, allowed_by_default); |
| 984 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy()); | 999 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy()); |
| 985 args->SetInteger(webview::kRequestId, request_id); | 1000 args->SetInteger(webview::kRequestId, request_id); |
| 986 switch (static_cast<int>(permission_type)) { | 1001 switch (static_cast<int>(permission_type)) { |
| 987 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: { | 1002 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: { |
| 988 DispatchEvent( | 1003 DispatchEvent(new GuestView::Event(webview::kEventNewWindow, |
| 989 new GuestViewBase::Event(webview::kEventNewWindow, args.Pass())); | 1004 args.Pass())); |
| 990 break; | 1005 break; |
| 991 } | 1006 } |
| 992 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: { | 1007 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: { |
| 993 DispatchEvent( | 1008 DispatchEvent(new GuestView::Event(webview::kEventDialog, |
| 994 new GuestViewBase::Event(webview::kEventDialog, args.Pass())); | 1009 args.Pass())); |
| 995 break; | 1010 break; |
| 996 } | 1011 } |
| 997 default: { | 1012 default: { |
| 998 args->SetString(webview::kPermission, | 1013 args->SetString(webview::kPermission, |
| 999 PermissionTypeToString(permission_type)); | 1014 PermissionTypeToString(permission_type)); |
| 1000 DispatchEvent(new GuestViewBase::Event(webview::kEventPermissionRequest, | 1015 DispatchEvent(new GuestView::Event(webview::kEventPermissionRequest, |
| 1001 args.Pass())); | 1016 args.Pass())); |
| 1002 break; | 1017 break; |
| 1003 } | 1018 } |
| 1004 } | 1019 } |
| 1005 return request_id; | 1020 return request_id; |
| 1006 } | 1021 } |
| 1007 | 1022 |
| 1008 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo() | 1023 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo() |
| 1009 : permission_type(BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN), | 1024 : permission_type(BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN), |
| 1010 allowed_by_default(false) { | 1025 allowed_by_default(false) { |
| 1011 } | 1026 } |
| 1012 | 1027 |
| 1013 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo( | 1028 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo( |
| 1014 const PermissionResponseCallback& callback, | 1029 const PermissionResponseCallback& callback, |
| 1015 BrowserPluginPermissionType permission_type, | 1030 BrowserPluginPermissionType permission_type, |
| 1016 bool allowed_by_default) | 1031 bool allowed_by_default) |
| 1017 : callback(callback), | 1032 : callback(callback), |
| 1018 permission_type(permission_type), | 1033 permission_type(permission_type), |
| 1019 allowed_by_default(allowed_by_default) { | 1034 allowed_by_default(allowed_by_default) { |
| 1020 } | 1035 } |
| 1021 | 1036 |
| 1022 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { | 1037 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { |
| 1023 } | 1038 } |
| OLD | NEW |