| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_browser_event_router.h" | 5 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/extension_event_names.h" | 9 #include "chrome/browser/extensions/extension_event_names.h" |
| 10 #include "chrome/browser/extensions/extension_event_router.h" | 10 #include "chrome/browser/extensions/extension_event_router.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 | 24 |
| 25 #if defined(TOOLKIT_GTK) | 25 #if defined(TOOLKIT_GTK) |
| 26 #include "ui/base/x/active_window_watcher_x.h" | 26 #include "ui/base/x/active_window_watcher_x.h" |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 namespace events = extension_event_names; | 29 namespace events = extension_event_names; |
| 30 namespace tab_keys = extension_tabs_module_constants; | 30 namespace tab_keys = extension_tabs_module_constants; |
| 31 namespace page_action_keys = extension_page_actions_module_constants; | 31 namespace page_action_keys = extension_page_actions_module_constants; |
| 32 | 32 |
| 33 using content::NavigationController; |
| 33 using content::WebContents; | 34 using content::WebContents; |
| 34 | 35 |
| 35 ExtensionBrowserEventRouter::TabEntry::TabEntry() | 36 ExtensionBrowserEventRouter::TabEntry::TabEntry() |
| 36 : complete_waiting_on_load_(false), | 37 : complete_waiting_on_load_(false), |
| 37 url_() { | 38 url_() { |
| 38 } | 39 } |
| 39 | 40 |
| 40 DictionaryValue* ExtensionBrowserEventRouter::TabEntry::UpdateLoadState( | 41 DictionaryValue* ExtensionBrowserEventRouter::TabEntry::UpdateLoadState( |
| 41 const WebContents* contents) { | 42 const WebContents* contents) { |
| 42 // The tab may go in & out of loading (for instance if iframes navigate). | 43 // The tab may go in & out of loading (for instance if iframes navigate). |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 for (int i = 0; i < browser->tabstrip_model()->count(); ++i) { | 143 for (int i = 0; i < browser->tabstrip_model()->count(); ++i) { |
| 143 RegisterForTabNotifications( | 144 RegisterForTabNotifications( |
| 144 browser->GetTabContentsWrapperAt(i)->web_contents()); | 145 browser->GetTabContentsWrapperAt(i)->web_contents()); |
| 145 } | 146 } |
| 146 } | 147 } |
| 147 | 148 |
| 148 void ExtensionBrowserEventRouter::RegisterForTabNotifications( | 149 void ExtensionBrowserEventRouter::RegisterForTabNotifications( |
| 149 WebContents* contents) { | 150 WebContents* contents) { |
| 150 registrar_.Add( | 151 registrar_.Add( |
| 151 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 152 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 152 content::Source<content::NavigationController>( | 153 content::Source<NavigationController>(&contents->GetController())); |
| 153 &contents->GetController())); | |
| 154 | 154 |
| 155 // Observing TAB_CONTENTS_DESTROYED is necessary because it's | 155 // Observing TAB_CONTENTS_DESTROYED is necessary because it's |
| 156 // possible for tabs to be created, detached and then destroyed without | 156 // possible for tabs to be created, detached and then destroyed without |
| 157 // ever having been re-attached and closed. This happens in the case of | 157 // ever having been re-attached and closed. This happens in the case of |
| 158 // a devtools TabContents that is opened in window, docked, then closed. | 158 // a devtools TabContents that is opened in window, docked, then closed. |
| 159 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 159 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 160 content::Source<WebContents>(contents)); | 160 content::Source<WebContents>(contents)); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void ExtensionBrowserEventRouter::UnregisterForTabNotifications( | 163 void ExtensionBrowserEventRouter::UnregisterForTabNotifications( |
| 164 WebContents* contents) { | 164 WebContents* contents) { |
| 165 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 165 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 166 content::Source<content::NavigationController>( | 166 content::Source<NavigationController>(&contents->GetController())); |
| 167 &contents->GetController())); | |
| 168 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 167 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 169 content::Source<WebContents>(contents)); | 168 content::Source<WebContents>(contents)); |
| 170 } | 169 } |
| 171 | 170 |
| 172 void ExtensionBrowserEventRouter::OnBrowserWindowReady(const Browser* browser) { | 171 void ExtensionBrowserEventRouter::OnBrowserWindowReady(const Browser* browser) { |
| 173 ListValue args; | 172 ListValue args; |
| 174 | 173 |
| 175 DictionaryValue* window_dictionary = ExtensionTabUtil::CreateWindowValue( | 174 DictionaryValue* window_dictionary = ExtensionTabUtil::CreateWindowValue( |
| 176 browser, false); | 175 browser, false); |
| 177 args.Append(window_dictionary); | 176 args.Append(window_dictionary); |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 if (tab_entries_.end() == i) | 534 if (tab_entries_.end() == i) |
| 536 return NULL; | 535 return NULL; |
| 537 return &i->second; | 536 return &i->second; |
| 538 } | 537 } |
| 539 | 538 |
| 540 void ExtensionBrowserEventRouter::Observe( | 539 void ExtensionBrowserEventRouter::Observe( |
| 541 int type, | 540 int type, |
| 542 const content::NotificationSource& source, | 541 const content::NotificationSource& source, |
| 543 const content::NotificationDetails& details) { | 542 const content::NotificationDetails& details) { |
| 544 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { | 543 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { |
| 545 content::NavigationController* source_controller = | 544 NavigationController* source_controller = |
| 546 content::Source<content::NavigationController>(source).ptr(); | 545 content::Source<NavigationController>(source).ptr(); |
| 547 TabUpdated(source_controller->GetWebContents(), true); | 546 TabUpdated(source_controller->GetWebContents(), true); |
| 548 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 547 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
| 549 // Tab was destroyed after being detached (without being re-attached). | 548 // Tab was destroyed after being detached (without being re-attached). |
| 550 WebContents* contents = content::Source<WebContents>(source).ptr(); | 549 WebContents* contents = content::Source<WebContents>(source).ptr(); |
| 551 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 550 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 552 content::Source<content::NavigationController>( | 551 content::Source<NavigationController>(&contents->GetController())); |
| 553 &contents->GetController())); | |
| 554 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 552 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 555 content::Source<WebContents>(contents)); | 553 content::Source<WebContents>(contents)); |
| 556 } else if (type == chrome::NOTIFICATION_BROWSER_WINDOW_READY) { | 554 } else if (type == chrome::NOTIFICATION_BROWSER_WINDOW_READY) { |
| 557 const Browser* browser = content::Source<const Browser>(source).ptr(); | 555 const Browser* browser = content::Source<const Browser>(source).ptr(); |
| 558 OnBrowserWindowReady(browser); | 556 OnBrowserWindowReady(browser); |
| 559 #if defined(OS_MACOSX) | 557 #if defined(OS_MACOSX) |
| 560 } else if (type == content::NOTIFICATION_NO_KEY_WINDOW) { | 558 } else if (type == content::NOTIFICATION_NO_KEY_WINDOW) { |
| 561 OnBrowserSetLastActive(NULL); | 559 OnBrowserSetLastActive(NULL); |
| 562 #endif | 560 #endif |
| 563 } else { | 561 } else { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 | 637 |
| 640 void ExtensionBrowserEventRouter::BrowserActionExecuted( | 638 void ExtensionBrowserEventRouter::BrowserActionExecuted( |
| 641 Profile* profile, const std::string& extension_id, Browser* browser) { | 639 Profile* profile, const std::string& extension_id, Browser* browser) { |
| 642 TabContentsWrapper* tab_contents = NULL; | 640 TabContentsWrapper* tab_contents = NULL; |
| 643 int tab_id = 0; | 641 int tab_id = 0; |
| 644 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id)) | 642 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id)) |
| 645 return; | 643 return; |
| 646 DispatchEventWithTab(profile, extension_id, "browserAction.onClicked", | 644 DispatchEventWithTab(profile, extension_id, "browserAction.onClicked", |
| 647 tab_contents->web_contents(), true); | 645 tab_contents->web_contents(), true); |
| 648 } | 646 } |
| OLD | NEW |