| Index: chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
|
| diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
|
| index c483f855d61a0df4e122227e686c39541f63dd96..b57ba81c5b0da8929c07758a9c2c941f7b62ca23 100644
|
| --- a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
|
| +++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
|
| @@ -50,6 +50,12 @@ typedef std::map<content::WebContents*, WebNavigationTabObserver*>
|
| static base::LazyInstance<TabObserverMap> g_tab_observer =
|
| LAZY_INSTANCE_INITIALIZER;
|
|
|
| +typedef std::map<content::WebContents*,
|
| + WebNavigationEventRouter::PendingWebContents>
|
| + PendingWebContentsMap;
|
| +static base::LazyInstance<PendingWebContentsMap> g_pending_web_contents =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| +
|
| } // namespace
|
|
|
| // WebNavigtionEventRouter -------------------------------------------
|
| @@ -124,6 +130,7 @@ void WebNavigationEventRouter::Observe(
|
| const content::NotificationDetails& details) {
|
| switch (type) {
|
| case chrome::NOTIFICATION_RETARGETING: {
|
| + LOG(ERROR) << "WNTO::Observe: retargeting";
|
| Profile* profile = content::Source<Profile>(source).ptr();
|
| if (profile->GetOriginalProfile() == profile_) {
|
| Retargeting(
|
| @@ -133,10 +140,12 @@ void WebNavigationEventRouter::Observe(
|
| }
|
|
|
| case chrome::NOTIFICATION_TAB_ADDED:
|
| + LOG(ERROR) << "WNTO::Observe: tab added";
|
| TabAdded(content::Details<content::WebContents>(details).ptr());
|
| break;
|
|
|
| case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
|
| + LOG(ERROR) << "WNTO::Observe: web contents destroyed";
|
| TabDestroyed(content::Source<content::WebContents>(source).ptr());
|
| break;
|
|
|
| @@ -146,6 +155,11 @@ void WebNavigationEventRouter::Observe(
|
| }
|
|
|
| void WebNavigationEventRouter::Retargeting(const RetargetingDetails* details) {
|
| + LOG(ERROR) << "WNER::Retargeting: "
|
| + << " url:" << details->target_url
|
| + << " source wc:" << details->source_web_contents
|
| + << " target wc:" << details->target_web_contents
|
| + << " not yet in ts:" << details->not_yet_in_tabstrip;
|
| if (details->source_render_frame_id == 0)
|
| return;
|
| WebNavigationTabObserver* tab_observer =
|
| @@ -167,11 +181,9 @@ void WebNavigationEventRouter::Retargeting(const RetargetingDetails* details) {
|
| // If the WebContents isn't yet inserted into a tab strip, we need to delay
|
| // the extension event until the WebContents is fully initialized.
|
| if (details->not_yet_in_tabstrip) {
|
| - pending_web_contents_[details->target_web_contents] =
|
| - PendingWebContents(details->source_web_contents,
|
| - frame_host,
|
| - details->target_web_contents,
|
| - details->target_url);
|
| + g_pending_web_contents.Get()[details->target_web_contents] =
|
| + PendingWebContents(details->source_web_contents, frame_host,
|
| + details->target_web_contents, details->target_url);
|
| } else {
|
| helpers::DispatchOnCreatedNavigationTarget(
|
| details->source_web_contents,
|
| @@ -184,8 +196,8 @@ void WebNavigationEventRouter::Retargeting(const RetargetingDetails* details) {
|
|
|
| void WebNavigationEventRouter::TabAdded(content::WebContents* tab) {
|
| std::map<content::WebContents*, PendingWebContents>::iterator iter =
|
| - pending_web_contents_.find(tab);
|
| - if (iter == pending_web_contents_.end())
|
| + g_pending_web_contents.Get().find(tab);
|
| + if (iter == g_pending_web_contents.Get().end())
|
| return;
|
|
|
| WebNavigationTabObserver* tab_observer =
|
| @@ -205,15 +217,16 @@ void WebNavigationEventRouter::TabAdded(content::WebContents* tab) {
|
| iter->second.target_web_contents,
|
| iter->second.target_url);
|
| }
|
| - pending_web_contents_.erase(iter);
|
| + g_pending_web_contents.Get().erase(iter);
|
| }
|
|
|
| void WebNavigationEventRouter::TabDestroyed(content::WebContents* tab) {
|
| - pending_web_contents_.erase(tab);
|
| + g_pending_web_contents.Get().erase(tab);
|
| for (std::map<content::WebContents*, PendingWebContents>::iterator i =
|
| - pending_web_contents_.begin(); i != pending_web_contents_.end(); ) {
|
| + g_pending_web_contents.Get().begin();
|
| + i != g_pending_web_contents.Get().end();) {
|
| if (i->second.source_web_contents == tab)
|
| - pending_web_contents_.erase(i++);
|
| + g_pending_web_contents.Get().erase(i++);
|
| else
|
| ++i;
|
| }
|
| @@ -268,6 +281,7 @@ void WebNavigationTabObserver::RenderFrameHostChanged(
|
|
|
| void WebNavigationTabObserver::DidStartNavigation(
|
| content::NavigationHandle* navigation_handle) {
|
| + LOG(ERROR) << "WNTP::DidStartNavigation: handle:" << navigation_handle;
|
| if (navigation_handle->IsSynchronousNavigation() ||
|
| !FrameNavigationState::IsValidUrl(navigation_handle->GetURL())) {
|
| return;
|
| @@ -278,6 +292,7 @@ void WebNavigationTabObserver::DidStartNavigation(
|
|
|
| void WebNavigationTabObserver::DidFinishNavigation(
|
| content::NavigationHandle* navigation_handle) {
|
| + LOG(ERROR) << "WNTP::DidFinishNavigation: handle:" << navigation_handle;
|
| if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) {
|
| HandleCommit(navigation_handle);
|
| return;
|
| @@ -368,6 +383,11 @@ void WebNavigationTabObserver::DidOpenRequestedURL(
|
| const content::Referrer& referrer,
|
| WindowOpenDisposition disposition,
|
| ui::PageTransition transition) {
|
| + LOG(ERROR) << "WNTO::DidOpenRequestedURL: "
|
| + << " new_contents:" << new_contents << " url:" << url
|
| + << " disposition:" << (int)disposition
|
| + << " source rfh:" << source_render_frame_host;
|
| +
|
| if (!navigation_state_.CanSendEvents(source_render_frame_host))
|
| return;
|
|
|
| @@ -381,6 +401,19 @@ void WebNavigationTabObserver::DidOpenRequestedURL(
|
| disposition != WindowOpenDisposition::OFF_THE_RECORD)
|
| return;
|
|
|
| + if (!ExtensionTabUtil::GetTabById(
|
| + ExtensionTabUtil::GetTabId(new_contents),
|
| + Profile::FromBrowserContext(new_contents->GetBrowserContext()), false,
|
| + NULL, NULL, NULL, NULL)) {
|
| + DCHECK_EQ(web_contents(), content::WebContents::FromRenderFrameHost(
|
| + source_render_frame_host));
|
| +
|
| + g_pending_web_contents.Get()[new_contents] =
|
| + WebNavigationEventRouter::PendingWebContents(
|
| + web_contents(), source_render_frame_host, new_contents, url);
|
| + return;
|
| + }
|
| +
|
| helpers::DispatchOnCreatedNavigationTarget(web_contents(),
|
| new_contents->GetBrowserContext(),
|
| source_render_frame_host,
|
|
|