summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 15:52:38 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 15:52:38 +0000
commit201c794ddcdfae349c890bdcee643753ab559f8e (patch)
treed72242b838931df0c46fcbbd8ca7484e4940fb97
parent1fbde4f1700cb379f33d9cb6edb66e573dfbb85e (diff)
downloadchromium_src-201c794ddcdfae349c890bdcee643753ab559f8e.zip
chromium_src-201c794ddcdfae349c890bdcee643753ab559f8e.tar.gz
chromium_src-201c794ddcdfae349c890bdcee643753ab559f8e.tar.bz2
Include the information whether the tab is already in a tab strip with the retargeting details
BUG=107759 TEST=added a DCHECK. Without the fix, the DCHECK would trigger in ExtensionApiTest.WebNavigationOpenTab Review URL: http://codereview.chromium.org/8964014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114806 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_tab_id_map.cc10
-rw-r--r--chrome/browser/extensions/extension_webnavigation_api.cc31
-rw-r--r--chrome/browser/extensions/extension_webnavigation_api.h4
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc13
-rw-r--r--chrome/browser/tab_contents/render_view_host_delegate_helper.cc12
-rw-r--r--chrome/browser/tab_contents/retargeting_details.h31
-rw-r--r--chrome/chrome_browser.gypi1
-rw-r--r--chrome/common/chrome_notification_types.h6
-rw-r--r--content/browser/tab_contents/navigation_details.h15
-rw-r--r--content/public/browser/notification_types.h7
10 files changed, 81 insertions, 49 deletions
diff --git a/chrome/browser/extensions/extension_tab_id_map.cc b/chrome/browser/extensions/extension_tab_id_map.cc
index f799dd1..e4cfacd 100644
--- a/chrome/browser/extensions/extension_tab_id_map.cc
+++ b/chrome/browser/extensions/extension_tab_id_map.cc
@@ -7,7 +7,9 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "chrome/browser/sessions/restore_tab_helper.h"
+#include "chrome/browser/tab_contents/retargeting_details.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/common/chrome_notification_types.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/navigation_details.h"
#include "content/browser/tab_contents/tab_contents.h"
@@ -48,7 +50,7 @@ ExtensionTabIdMap::TabObserver::TabObserver() {
content::NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, content::NOTIFICATION_TAB_PARENTED,
content::NotificationService::AllBrowserContextsAndSources());
- registrar_.Add(this, content::NOTIFICATION_RETARGETING,
+ registrar_.Add(this, chrome::NOTIFICATION_RETARGETING,
content::NotificationService::AllBrowserContextsAndSources());
}
@@ -93,9 +95,9 @@ void ExtensionTabIdMap::TabObserver::Observe(
tab->restore_tab_helper()->window_id().id()));
break;
}
- case content::NOTIFICATION_RETARGETING: {
- content::RetargetingDetails* retargeting_details =
- content::Details<content::RetargetingDetails>(details).ptr();
+ case chrome::NOTIFICATION_RETARGETING: {
+ RetargetingDetails* retargeting_details =
+ content::Details<RetargetingDetails>(details).ptr();
TabContents* contents = retargeting_details->target_tab_contents;
TabContentsWrapper* tab =
TabContentsWrapper::GetCurrentWrapperForContents(contents);
diff --git a/chrome/browser/extensions/extension_webnavigation_api.cc b/chrome/browser/extensions/extension_webnavigation_api.cc
index 9f7a9c0..c79eae6 100644
--- a/chrome/browser/extensions/extension_webnavigation_api.cc
+++ b/chrome/browser/extensions/extension_webnavigation_api.cc
@@ -15,7 +15,9 @@
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/extension_webnavigation_api_constants.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/tab_contents/retargeting_details.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/url_constants.h"
#include "content/browser/tab_contents/navigation_details.h"
#include "content/browser/tab_contents/tab_contents.h"
@@ -171,6 +173,13 @@ void DispatchOnCreatedNavigationTarget(
bool source_frame_is_main_frame,
TabContents* target_tab_contents,
const GURL& target_url) {
+ // Check that the tab is already inserted into a tab strip model. This code
+ // path is exercised by ExtensionApiTest.WebNavigationRequestOpenTab.
+ DCHECK(ExtensionTabUtil::GetTabById(
+ ExtensionTabUtil::GetTabId(target_tab_contents),
+ Profile::FromBrowserContext(target_tab_contents->browser_context()),
+ false, NULL, NULL, NULL, NULL));
+
ListValue args;
DictionaryValue* dict = new DictionaryValue();
dict->SetInteger(keys::kSourceTabIdKey,
@@ -363,8 +372,8 @@ ExtensionWebNavigationEventRouter::~ExtensionWebNavigationEventRouter() {}
void ExtensionWebNavigationEventRouter::Init() {
if (registrar_.IsEmpty()) {
registrar_.Add(this,
- content::NOTIFICATION_RETARGETING,
- content::Source<content::BrowserContext>(profile_));
+ chrome::NOTIFICATION_RETARGETING,
+ content::Source<Profile>(profile_));
registrar_.Add(this,
content::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources());
@@ -379,9 +388,9 @@ void ExtensionWebNavigationEventRouter::Observe(
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
- case content::NOTIFICATION_RETARGETING:
+ case chrome::NOTIFICATION_RETARGETING:
Retargeting(
- content::Details<const content::RetargetingDetails>(details).ptr());
+ content::Details<const RetargetingDetails>(details).ptr());
break;
case content::NOTIFICATION_TAB_ADDED:
@@ -398,7 +407,7 @@ void ExtensionWebNavigationEventRouter::Observe(
}
void ExtensionWebNavigationEventRouter::Retargeting(
- const content::RetargetingDetails* details) {
+ const RetargetingDetails* details) {
if (details->source_frame_id == 0)
return;
ExtensionWebNavigationTabObserver* tab_observer =
@@ -414,11 +423,13 @@ void ExtensionWebNavigationEventRouter::Retargeting(
if (!frame_navigation_state.CanSendEvents(details->source_frame_id))
return;
- // If the TabContents was created as a response to an IPC from a renderer, it
- // doesn't yet have a wrapper, and we need to delay the extension event until
- // the TabContents is fully initialized.
- if (TabContentsWrapper::GetCurrentWrapperForContents(
- details->target_tab_contents) == NULL) {
+ // If the TabContents was created as a response to an IPC from a renderer
+ // (and therefore doesn't yet have a wrapper), or if it isn't yet inserted
+ // into a tab strip, we need to delay the extension event until the
+ // TabContents is fully initialized.
+ if ((TabContentsWrapper::GetCurrentWrapperForContents(
+ details->target_tab_contents) == NULL) ||
+ details->not_yet_in_tabstrip) {
pending_tab_contents_[details->target_tab_contents] =
PendingTabContents(
details->source_tab_contents,
diff --git a/chrome/browser/extensions/extension_webnavigation_api.h b/chrome/browser/extensions/extension_webnavigation_api.h
index 4eb9cae..d3a25be 100644
--- a/chrome/browser/extensions/extension_webnavigation_api.h
+++ b/chrome/browser/extensions/extension_webnavigation_api.h
@@ -20,9 +20,7 @@
#include "content/public/browser/notification_registrar.h"
#include "googleurl/src/gurl.h"
-namespace content {
struct RetargetingDetails;
-}
class TabContents;
// Tracks the navigation state of all frames in a given tab currently known to
@@ -207,7 +205,7 @@ class ExtensionWebNavigationEventRouter : public content::NotificationObserver {
// Handler for the NOTIFICATION_RETARGETING event. The method takes the
// details of such an event and stores them for the later
// NOTIFICATION_TAB_ADDED event.
- void Retargeting(const content::RetargetingDetails* details);
+ void Retargeting(const RetargetingDetails* details);
// Handler for the NOTIFICATION_TAB_ADDED event. The method takes the details
// of such an event and creates a JSON formated extension event from it.
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 6532425..dd5ea04 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -40,6 +40,7 @@
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/spellchecker/spellcheck_host.h"
#include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
+#include "chrome/browser/tab_contents/retargeting_details.h"
#include "chrome/browser/tab_contents/spellchecker_submenu_observer.h"
#include "chrome/browser/tab_contents/spelling_menu_observer.h"
#include "chrome/browser/translate/translate_manager.h"
@@ -52,6 +53,7 @@
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/print_messages.h"
@@ -1830,16 +1832,17 @@ void RenderViewContextMenu::OpenURL(
transition, false));
if (new_contents) {
- content::RetargetingDetails details;
+ RetargetingDetails details;
details.source_tab_contents = source_tab_contents_;
details.source_frame_id = frame_id;
details.target_url = url;
details.target_tab_contents = new_contents;
+ details.not_yet_in_tabstrip = false;
content::NotificationService::current()->Notify(
- content::NOTIFICATION_RETARGETING,
- content::Source<content::BrowserContext>(
- source_tab_contents_->browser_context()),
- content::Details<content::RetargetingDetails>(&details));
+ chrome::NOTIFICATION_RETARGETING,
+ content::Source<Profile>(Profile::FromBrowserContext(
+ source_tab_contents_->browser_context())),
+ content::Details<RetargetingDetails>(&details));
}
}
diff --git a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
index 499af98..d1d871f 100644
--- a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
+++ b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/prerender/prerender_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/background_contents.h"
+#include "chrome/browser/tab_contents/retargeting_details.h"
#include "chrome/browser/user_style_sheet_watcher.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_view_type.h"
@@ -271,16 +272,17 @@ TabContents* RenderViewHostDelegateViewHelper::CreateNewWindowFromTabContents(
if (tab_contents->delegate())
tab_contents->delegate()->TabContentsCreated(new_contents);
- content::RetargetingDetails details;
+ RetargetingDetails details;
details.source_tab_contents = tab_contents;
details.source_frame_id = params.opener_frame_id;
details.target_url = params.target_url;
details.target_tab_contents = new_contents;
+ details.not_yet_in_tabstrip = true;
content::NotificationService::current()->Notify(
- content::NOTIFICATION_RETARGETING,
- content::Source<content::BrowserContext>(
- tab_contents->browser_context()),
- content::Details<content::RetargetingDetails>(&details));
+ chrome::NOTIFICATION_RETARGETING,
+ content::Source<Profile>(
+ Profile::FromBrowserContext(tab_contents->browser_context())),
+ content::Details<RetargetingDetails>(&details));
} else {
content::NotificationService::current()->Notify(
content::NOTIFICATION_CREATING_NEW_WINDOW_CANCELLED,
diff --git a/chrome/browser/tab_contents/retargeting_details.h b/chrome/browser/tab_contents/retargeting_details.h
new file mode 100644
index 0000000..988e8ee
--- /dev/null
+++ b/chrome/browser/tab_contents/retargeting_details.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_TAB_CONTENTS_RETARGETING_DETAILS_H_
+#define CHROME_BROWSER_TAB_CONTENTS_RETARGETING_DETAILS_H_
+#pragma once
+
+#include "googleurl/src/gurl.h"
+
+class TabContents;
+
+// Details sent for NOTIFICATION_RETARGETING.
+struct RetargetingDetails {
+ // The source tab contents.
+ TabContents* source_tab_contents;
+
+ // The frame ID of the source tab from which the retargeting was triggered.
+ int64 source_frame_id;
+
+ // The target URL.
+ GURL target_url;
+
+ // The target tab contents.
+ TabContents* target_tab_contents;
+
+ // True if the target_tab_contents is not yet inserted into a tab strip.
+ bool not_yet_in_tabstrip;
+};
+
+#endif // CHROME_BROWSER_TAB_CONTENTS_RETARGETING_DETAILS_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 7df0f91..5260d0c 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2370,6 +2370,7 @@
'browser/tab_contents/render_view_context_menu_observer.h',
'browser/tab_contents/render_view_host_delegate_helper.cc',
'browser/tab_contents/render_view_host_delegate_helper.h',
+ 'browser/tab_contents/retargeting_details.h',
'browser/tab_contents/tab_contents_ssl_helper.cc',
'browser/tab_contents/tab_contents_ssl_helper.h',
'browser/tab_contents/tab_contents_view_gtk.cc',
diff --git a/chrome/common/chrome_notification_types.h b/chrome/common/chrome_notification_types.h
index 069bcdd..f970cc4 100644
--- a/chrome/common/chrome_notification_types.h
+++ b/chrome/common/chrome_notification_types.h
@@ -76,6 +76,12 @@ enum NotificationType {
// for the shown dialog.
NOTIFICATION_HTML_DIALOG_SHOWN,
+ // A new tab is created from an existing tab to serve as a target of a
+ // navigation that is about to happen. The source will be a Source<Profile>
+ // corresponding to the profile in which the new tab will live. Details in
+ // the form of a RetargetingDetails object are provided.
+ NOTIFICATION_RETARGETING,
+
// Application-modal dialogs -----------------------------------------------
// Sent after an application-modal dialog has been shown. The source
diff --git a/content/browser/tab_contents/navigation_details.h b/content/browser/tab_contents/navigation_details.h
index 7145ae9..e671b84 100644
--- a/content/browser/tab_contents/navigation_details.h
+++ b/content/browser/tab_contents/navigation_details.h
@@ -87,21 +87,6 @@ struct PrunedDetails {
int count;
};
-// Details sent for NOTIFY_NAV_RETARGETING.
-struct RetargetingDetails {
- // The source tab contents.
- TabContents* source_tab_contents;
-
- // The frame ID of the source tab from which the retargeting was triggered.
- int64 source_frame_id;
-
- // The target URL.
- GURL target_url;
-
- // The target tab contents.
- TabContents* target_tab_contents;
-};
-
} // namespace content
#endif // CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_DETAILS_H_
diff --git a/content/public/browser/notification_types.h b/content/public/browser/notification_types.h
index 23f947a..e5d9654 100644
--- a/content/public/browser/notification_types.h
+++ b/content/public/browser/notification_types.h
@@ -120,13 +120,6 @@ enum NotificationType {
// are provided.
NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
- // A new tab is created from an existing tab to serve as a target of a
- // navigation that is about to happen. The source will be a
- // Source<BrowserContext> corresponding to the browser context in which the
- // new tab will live. Details in the form of a RetargetingDetails object are
- // provided.
- NOTIFICATION_RETARGETING,
-
// A new window was requested but was not created. The source will be a
// Source<TabContents> corresponding to the tab the request originated from.
// Details are the ViewHostMsg_CreateWindow_Params object that were used in