| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser_event_router.h" | 5 #include "chrome/browser/extensions/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/api/extension_action/extension_page_actions_
api_constants.h" | 9 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_
api_constants.h" |
| 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 tab_keys::kStatusValueLoading); | 67 tab_keys::kStatusValueLoading); |
| 68 | 68 |
| 69 if (contents->GetURL() != url_) { | 69 if (contents->GetURL() != url_) { |
| 70 url_ = contents->GetURL(); | 70 url_ = contents->GetURL(); |
| 71 changed_properties->SetString(tab_keys::kUrlKey, url_.spec()); | 71 changed_properties->SetString(tab_keys::kUrlKey, url_.spec()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 return changed_properties; | 74 return changed_properties; |
| 75 } | 75 } |
| 76 | 76 |
| 77 void BrowserEventRouter::Init() { | 77 BrowserEventRouter::BrowserEventRouter(Profile* profile) |
| 78 if (initialized_) | 78 : profile_(profile) { |
| 79 return; | 79 DCHECK(!profile->IsOffTheRecord()); |
| 80 |
| 80 BrowserList::AddObserver(this); | 81 BrowserList::AddObserver(this); |
| 81 | 82 |
| 82 // Init() can happen after the browser is running, so catch up with any | 83 // Init() can happen after the browser is running, so catch up with any |
| 83 // windows that already exist. | 84 // windows that already exist. |
| 84 for (BrowserList::const_iterator iter = BrowserList::begin(); | 85 for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 85 iter != BrowserList::end(); ++iter) { | 86 iter != BrowserList::end(); ++iter) { |
| 86 RegisterForBrowserNotifications(*iter); | 87 RegisterForBrowserNotifications(*iter); |
| 87 | 88 |
| 88 // Also catch up our internal bookkeeping of tab entries. | 89 // Also catch up our internal bookkeeping of tab entries. |
| 89 Browser* browser = *iter; | 90 Browser* browser = *iter; |
| 90 if (browser->tab_strip_model()) { | 91 if (browser->tab_strip_model()) { |
| 91 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { | 92 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { |
| 92 WebContents* contents = chrome::GetWebContentsAt(browser, i); | 93 WebContents* contents = chrome::GetWebContentsAt(browser, i); |
| 93 int tab_id = ExtensionTabUtil::GetTabId(contents); | 94 int tab_id = ExtensionTabUtil::GetTabId(contents); |
| 94 tab_entries_[tab_id] = TabEntry(); | 95 tab_entries_[tab_id] = TabEntry(); |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 } | 98 } |
| 98 | |
| 99 initialized_ = true; | |
| 100 } | |
| 101 | |
| 102 BrowserEventRouter::BrowserEventRouter(Profile* profile) | |
| 103 : initialized_(false), | |
| 104 profile_(profile) { | |
| 105 DCHECK(!profile->IsOffTheRecord()); | |
| 106 } | 99 } |
| 107 | 100 |
| 108 BrowserEventRouter::~BrowserEventRouter() { | 101 BrowserEventRouter::~BrowserEventRouter() { |
| 109 BrowserList::RemoveObserver(this); | 102 BrowserList::RemoveObserver(this); |
| 110 } | 103 } |
| 111 | 104 |
| 112 void BrowserEventRouter::OnBrowserAdded(Browser* browser) { | 105 void BrowserEventRouter::OnBrowserAdded(Browser* browser) { |
| 113 RegisterForBrowserNotifications(browser); | 106 RegisterForBrowserNotifications(browser); |
| 114 } | 107 } |
| 115 | 108 |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 | 592 |
| 600 DispatchEventToExtension(profile, | 593 DispatchEventToExtension(profile, |
| 601 extension_action.extension_id(), | 594 extension_action.extension_id(), |
| 602 event_name, | 595 event_name, |
| 603 args.Pass(), | 596 args.Pass(), |
| 604 EventRouter::USER_GESTURE_ENABLED); | 597 EventRouter::USER_GESTURE_ENABLED); |
| 605 } | 598 } |
| 606 } | 599 } |
| 607 | 600 |
| 608 } // namespace extensions | 601 } // namespace extensions |
| OLD | NEW |