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

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

Issue 334923002: Remove ContentBrowserClient::GuestWebContentsAttached (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_adview
Patch Set: Added missing file Created 6 years, 6 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"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 printing::PrintViewManagerBasic::CreateForWebContents(contents); 179 printing::PrintViewManagerBasic::CreateForWebContents(contents);
180 #endif // defined(ENABLE_FULL_PRINTING) 180 #endif // defined(ENABLE_FULL_PRINTING)
181 #endif // defined(ENABLE_PRINTING) 181 #endif // defined(ENABLE_PRINTING)
182 } 182 }
183 183
184 } // namespace 184 } // namespace
185 185
186 WebViewGuest::WebViewGuest(int guest_instance_id, 186 WebViewGuest::WebViewGuest(int guest_instance_id,
187 WebContents* guest_web_contents, 187 WebContents* guest_web_contents,
188 const std::string& embedder_extension_id) 188 const std::string& embedder_extension_id)
189 : GuestView<WebViewGuest>(guest_instance_id, 189 : GuestView<WebViewGuest>(guest_instance_id),
190 guest_web_contents,
191 embedder_extension_id),
192 script_executor_(new extensions::ScriptExecutor(guest_web_contents, 190 script_executor_(new extensions::ScriptExecutor(guest_web_contents,
193 &script_observers_)), 191 &script_observers_)),
194 pending_context_menu_request_id_(0), 192 pending_context_menu_request_id_(0),
195 next_permission_request_id_(0), 193 next_permission_request_id_(0),
196 is_overriding_user_agent_(false), 194 is_overriding_user_agent_(false),
197 pending_reload_on_attachment_(false), 195 pending_reload_on_attachment_(false),
lazyboy 2014/06/13 17:40:01 Remove this flag then?
Fady Samuel 2014/06/16 14:35:41 Done.
198 main_frame_id_(0), 196 main_frame_id_(0),
199 chromevox_injected_(false), 197 chromevox_injected_(false),
200 find_helper_(this), 198 find_helper_(this),
201 javascript_dialog_helper_(this) { 199 javascript_dialog_helper_(this) {
200 Init(guest_web_contents, embedder_extension_id);
202 notification_registrar_.Add( 201 notification_registrar_.Add(
203 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 202 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
204 content::Source<WebContents>(guest_web_contents)); 203 content::Source<WebContents>(guest_web_contents));
205 204
206 notification_registrar_.Add( 205 notification_registrar_.Add(
207 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, 206 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
208 content::Source<WebContents>(guest_web_contents)); 207 content::Source<WebContents>(guest_web_contents));
209 208
210 #if defined(OS_CHROMEOS) 209 #if defined(OS_CHROMEOS)
211 chromeos::AccessibilityManager* accessibility_manager = 210 chromeos::AccessibilityManager* accessibility_manager =
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 // TODO(lazyboy): We need to expose some kind of enum equivalent of 376 // TODO(lazyboy): We need to expose some kind of enum equivalent of
378 // |command_id| instead of plain integers. 377 // |command_id| instead of plain integers.
379 item_value->SetInteger(webview::kMenuItemCommandId, 378 item_value->SetInteger(webview::kMenuItemCommandId,
380 menu_model.GetCommandIdAt(i)); 379 menu_model.GetCommandIdAt(i));
381 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); 380 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i));
382 items->Append(item_value); 381 items->Append(item_value);
383 } 382 }
384 return items.Pass(); 383 return items.Pass();
385 } 384 }
386 385
387 void WebViewGuest::Attach(WebContents* embedder_web_contents, 386 void WebViewGuest::DidAttach() {
388 const base::DictionaryValue& args) { 387 AddWebViewToExtensionRendererState();
388
389 std::string name; 389 std::string name;
390 args.GetString(webview::kName, &name); 390 if (extra_params()->GetString(webview::kName, &name)) {
391 // If the guest window's name is empty, then the WebView tag's name is 391 // If the guest window's name is empty, then the WebView tag's name is
392 // assigned. Otherwise, the guest window's name takes precedence over the 392 // assigned. Otherwise, the guest window's name takes precedence over the
393 // WebView tag's name. 393 // WebView tag's name.
394 if (name_.empty()) 394 if (name_.empty())
395 name_ = name; 395 name_ = name;
396 }
396 ReportFrameNameChange(name_); 397 ReportFrameNameChange(name_);
397 398
398 std::string user_agent_override; 399 std::string user_agent_override;
399 if (args.GetString(webview::kParameterUserAgentOverride, 400 if (extra_params()->GetString(webview::kParameterUserAgentOverride,
400 &user_agent_override)) { 401 &user_agent_override)) {
401 SetUserAgentOverride(user_agent_override); 402 SetUserAgentOverride(user_agent_override);
402 } else { 403 } else {
403 SetUserAgentOverride(""); 404 SetUserAgentOverride("");
404 } 405 }
405 406
406 GuestViewBase::Attach(embedder_web_contents, args); 407 std::string src;
408 if (extra_params()->GetString("src", &src) && !src.empty())
409 NavigateGuest(src);
407 410
408 AddWebViewToExtensionRendererState(); 411 if (GetOpener()) {
412 // We need to do a navigation here if the target URL has changed between
413 // the time the WebContents was created and the time it was attached.
414 // We also need to do an initial navigation if a RenderView was never
415 // created for the new window in cases where there is no referrer.
416 PendingWindowMap::iterator it =
417 GetOpener()->pending_new_windows_.find(this);
418 if (it != GetOpener()->pending_new_windows_.end()) {
419 const NewWindowInfo& new_window_info = it->second;
420 NavigateGuest(new_window_info.url.spec());
421 } else {
422 NOTREACHED();
423 }
424
425 // Once a new guest is attached to the DOM of the embedder page, then the
426 // lifetime of the new guest is no longer managed by the opener guest.
427 GetOpener()->pending_new_windows_.erase(this);
428 }
409 } 429 }
410 430
411 void WebViewGuest::DidStopLoading() { 431 void WebViewGuest::DidStopLoading() {
412 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 432 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
413 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); 433 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass()));
414 } 434 }
415 435
416 void WebViewGuest::EmbedderDestroyed() { 436 void WebViewGuest::EmbedderDestroyed() {
417 // TODO(fsamuel): WebRequest event listeners for <webview> should survive 437 // TODO(fsamuel): WebRequest event listeners for <webview> should survive
418 // reparenting of a <webview> within a single embedder. Right now, we keep 438 // reparenting of a <webview> within a single embedder. Right now, we keep
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 DispatchEvent( 485 DispatchEvent(
466 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass())); 486 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass()));
467 return true; 487 return true;
468 } 488 }
469 489
470 void WebViewGuest::CloseContents(WebContents* source) { 490 void WebViewGuest::CloseContents(WebContents* source) {
471 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 491 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
472 DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass())); 492 DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass()));
473 } 493 }
474 494
475 void WebViewGuest::DidAttach(const base::DictionaryValue& extra_params) {
476 std::string src;
477 if (extra_params.GetString("src", &src) && !src.empty())
478 NavigateGuest(src);
479
480 if (GetOpener()) {
481 // We need to do a navigation here if the target URL has changed between
482 // the time the WebContents was created and the time it was attached.
483 // We also need to do an initial navigation if a RenderView was never
484 // created for the new window in cases where there is no referrer.
485 PendingWindowMap::iterator it =
486 GetOpener()->pending_new_windows_.find(this);
487 if (it != GetOpener()->pending_new_windows_.end()) {
488 const NewWindowInfo& new_window_info = it->second;
489 NavigateGuest(new_window_info.url.spec());
490 } else {
491 NOTREACHED();
492 }
493
494 // Once a new guest is attached to the DOM of the embedder page, then the
495 // lifetime of the new guest is no longer managed by the opener guest.
496 GetOpener()->pending_new_windows_.erase(this);
497 }
498
499 if (pending_reload_on_attachment_) {
500 pending_reload_on_attachment_ = false;
501 guest_web_contents()->GetController().Reload(false);
502 }
503 }
504
505 void WebViewGuest::FindReply(WebContents* source, 495 void WebViewGuest::FindReply(WebContents* source,
506 int request_id, 496 int request_id,
507 int number_of_matches, 497 int number_of_matches,
508 const gfx::Rect& selection_rect, 498 const gfx::Rect& selection_rect,
509 int active_match_ordinal, 499 int active_match_ordinal,
510 bool final_update) { 500 bool final_update) {
511 find_helper_.FindReply(request_id, number_of_matches, selection_rect, 501 find_helper_.FindReply(request_id, number_of_matches, selection_rect,
512 active_match_ordinal, final_update); 502 active_match_ordinal, final_update);
513 } 503 }
514 504
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 if (action != DEFAULT) 826 if (action != DEFAULT)
837 RecordUserInitiatedUMA(info, allow); 827 RecordUserInitiatedUMA(info, allow);
838 828
839 pending_permission_requests_.erase(request_itr); 829 pending_permission_requests_.erase(request_itr);
840 830
841 return allow ? SET_PERMISSION_ALLOWED : SET_PERMISSION_DENIED; 831 return allow ? SET_PERMISSION_ALLOWED : SET_PERMISSION_DENIED;
842 } 832 }
843 833
844 void WebViewGuest::SetUserAgentOverride( 834 void WebViewGuest::SetUserAgentOverride(
845 const std::string& user_agent_override) { 835 const std::string& user_agent_override) {
836 if (!attached())
837 return;
846 is_overriding_user_agent_ = !user_agent_override.empty(); 838 is_overriding_user_agent_ = !user_agent_override.empty();
847 if (is_overriding_user_agent_) { 839 if (is_overriding_user_agent_) {
848 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA")); 840 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA"));
849 } 841 }
850 guest_web_contents()->SetUserAgentOverride(user_agent_override); 842 guest_web_contents()->SetUserAgentOverride(user_agent_override);
851 } 843 }
852 844
853 void WebViewGuest::Stop() { 845 void WebViewGuest::Stop() {
854 guest_web_contents()->Stop(); 846 guest_web_contents()->Stop();
855 } 847 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass())); 1041 DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass()));
1050 } 1042 }
1051 1043
1052 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { 1044 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) {
1053 content::NavigationController& controller = 1045 content::NavigationController& controller =
1054 guest_web_contents()->GetController(); 1046 guest_web_contents()->GetController();
1055 content::NavigationEntry* entry = controller.GetVisibleEntry(); 1047 content::NavigationEntry* entry = controller.GetVisibleEntry();
1056 if (!entry) 1048 if (!entry)
1057 return; 1049 return;
1058 entry->SetIsOverridingUserAgent(!user_agent.empty()); 1050 entry->SetIsOverridingUserAgent(!user_agent.empty());
1059 if (!attached()) {
1060 // We cannot reload now because all resource loads are suspended until
1061 // attachment.
1062 pending_reload_on_attachment_ = true;
1063 return;
1064 }
1065 guest_web_contents()->GetController().Reload(false); 1051 guest_web_contents()->GetController().Reload(false);
1066 } 1052 }
1067 1053
1068 void WebViewGuest::RenderViewReady() { 1054 void WebViewGuest::RenderViewReady() {
1069 // The guest RenderView should always live in an isolated guest process. 1055 // The guest RenderView should always live in an isolated guest process.
1070 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); 1056 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest());
1071 Send(new ChromeViewMsg_SetName(guest_web_contents()->GetRoutingID(), name_)); 1057 Send(new ChromeViewMsg_SetName(guest_web_contents()->GetRoutingID(), name_));
1072 } 1058 }
1073 1059
1074 void WebViewGuest::ReportFrameNameChange(const std::string& name) { 1060 void WebViewGuest::ReportFrameNameChange(const std::string& name) {
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 bool allow, 1575 bool allow,
1590 const std::string& user_input) { 1576 const std::string& user_input) {
1591 WebViewGuest* guest = 1577 WebViewGuest* guest =
1592 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1578 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1593 if (!guest) 1579 if (!guest)
1594 return; 1580 return;
1595 1581
1596 if (!allow) 1582 if (!allow)
1597 guest->Destroy(); 1583 guest->Destroy();
1598 } 1584 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698