| Index: chrome/browser/guest_view/web_view/web_view_guest.cc
|
| diff --git a/chrome/browser/guest_view/web_view/web_view_guest.cc b/chrome/browser/guest_view/web_view/web_view_guest.cc
|
| index 0faf2bafa9b1990664fd47147d36cda21dab5aa0..a50cb468edaf94e006457bc3e6bd437491cf3d2b 100644
|
| --- a/chrome/browser/guest_view/web_view/web_view_guest.cc
|
| +++ b/chrome/browser/guest_view/web_view/web_view_guest.cc
|
| @@ -186,9 +186,7 @@ void AttachWebViewHelpers(WebContents* contents) {
|
| WebViewGuest::WebViewGuest(int guest_instance_id,
|
| WebContents* guest_web_contents,
|
| const std::string& embedder_extension_id)
|
| - : GuestView<WebViewGuest>(guest_instance_id,
|
| - guest_web_contents,
|
| - embedder_extension_id),
|
| + : GuestView<WebViewGuest>(guest_instance_id),
|
| script_executor_(new extensions::ScriptExecutor(guest_web_contents,
|
| &script_observers_)),
|
| pending_context_menu_request_id_(0),
|
| @@ -199,6 +197,7 @@ WebViewGuest::WebViewGuest(int guest_instance_id,
|
| chromevox_injected_(false),
|
| find_helper_(this),
|
| javascript_dialog_helper_(this) {
|
| + Init(guest_web_contents, embedder_extension_id);
|
| notification_registrar_.Add(
|
| this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
|
| content::Source<WebContents>(guest_web_contents));
|
| @@ -384,28 +383,49 @@ scoped_ptr<base::ListValue> WebViewGuest::MenuModelToValue(
|
| return items.Pass();
|
| }
|
|
|
| -void WebViewGuest::Attach(WebContents* embedder_web_contents,
|
| - const base::DictionaryValue& args) {
|
| +void WebViewGuest::DidAttach() {
|
| + AddWebViewToExtensionRendererState();
|
| +
|
| std::string name;
|
| - args.GetString(webview::kName, &name);
|
| - // If the guest window's name is empty, then the WebView tag's name is
|
| - // assigned. Otherwise, the guest window's name takes precedence over the
|
| - // WebView tag's name.
|
| - if (name_.empty())
|
| - name_ = name;
|
| + if (extra_params()->GetString(webview::kName, &name)) {
|
| + // If the guest window's name is empty, then the WebView tag's name is
|
| + // assigned. Otherwise, the guest window's name takes precedence over the
|
| + // WebView tag's name.
|
| + if (name_.empty())
|
| + name_ = name;
|
| + }
|
| ReportFrameNameChange(name_);
|
|
|
| std::string user_agent_override;
|
| - if (args.GetString(webview::kParameterUserAgentOverride,
|
| - &user_agent_override)) {
|
| + if (extra_params()->GetString(webview::kParameterUserAgentOverride,
|
| + &user_agent_override)) {
|
| SetUserAgentOverride(user_agent_override);
|
| } else {
|
| SetUserAgentOverride("");
|
| }
|
|
|
| - GuestViewBase::Attach(embedder_web_contents, args);
|
| + std::string src;
|
| + if (extra_params()->GetString("src", &src) && !src.empty())
|
| + NavigateGuest(src);
|
|
|
| - AddWebViewToExtensionRendererState();
|
| + if (GetOpener()) {
|
| + // We need to do a navigation here if the target URL has changed between
|
| + // the time the WebContents was created and the time it was attached.
|
| + // We also need to do an initial navigation if a RenderView was never
|
| + // created for the new window in cases where there is no referrer.
|
| + PendingWindowMap::iterator it =
|
| + GetOpener()->pending_new_windows_.find(this);
|
| + if (it != GetOpener()->pending_new_windows_.end()) {
|
| + const NewWindowInfo& new_window_info = it->second;
|
| + NavigateGuest(new_window_info.url.spec());
|
| + } else {
|
| + NOTREACHED();
|
| + }
|
| +
|
| + // Once a new guest is attached to the DOM of the embedder page, then the
|
| + // lifetime of the new guest is no longer managed by the opener guest.
|
| + GetOpener()->pending_new_windows_.erase(this);
|
| + }
|
| }
|
|
|
| void WebViewGuest::DidStopLoading() {
|
| @@ -472,36 +492,6 @@ void WebViewGuest::CloseContents(WebContents* source) {
|
| DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass()));
|
| }
|
|
|
| -void WebViewGuest::DidAttach(const base::DictionaryValue& extra_params) {
|
| - std::string src;
|
| - if (extra_params.GetString("src", &src) && !src.empty())
|
| - NavigateGuest(src);
|
| -
|
| - if (GetOpener()) {
|
| - // We need to do a navigation here if the target URL has changed between
|
| - // the time the WebContents was created and the time it was attached.
|
| - // We also need to do an initial navigation if a RenderView was never
|
| - // created for the new window in cases where there is no referrer.
|
| - PendingWindowMap::iterator it =
|
| - GetOpener()->pending_new_windows_.find(this);
|
| - if (it != GetOpener()->pending_new_windows_.end()) {
|
| - const NewWindowInfo& new_window_info = it->second;
|
| - NavigateGuest(new_window_info.url.spec());
|
| - } else {
|
| - NOTREACHED();
|
| - }
|
| -
|
| - // Once a new guest is attached to the DOM of the embedder page, then the
|
| - // lifetime of the new guest is no longer managed by the opener guest.
|
| - GetOpener()->pending_new_windows_.erase(this);
|
| - }
|
| -
|
| - if (pending_reload_on_attachment_) {
|
| - pending_reload_on_attachment_ = false;
|
| - guest_web_contents()->GetController().Reload(false);
|
| - }
|
| -}
|
| -
|
| void WebViewGuest::FindReply(WebContents* source,
|
| int request_id,
|
| int number_of_matches,
|
| @@ -843,6 +833,8 @@ WebViewGuest::SetPermissionResult WebViewGuest::SetPermission(
|
|
|
| void WebViewGuest::SetUserAgentOverride(
|
| const std::string& user_agent_override) {
|
| + if (!attached())
|
| + return;
|
| is_overriding_user_agent_ = !user_agent_override.empty();
|
| if (is_overriding_user_agent_) {
|
| content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA"));
|
| @@ -1056,12 +1048,6 @@ void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) {
|
| if (!entry)
|
| return;
|
| entry->SetIsOverridingUserAgent(!user_agent.empty());
|
| - if (!attached()) {
|
| - // We cannot reload now because all resource loads are suspended until
|
| - // attachment.
|
| - pending_reload_on_attachment_ = true;
|
| - return;
|
| - }
|
| guest_web_contents()->GetController().Reload(false);
|
| }
|
|
|
|
|