Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: chrome/browser/extensions/extension_browser_event_router.cc

Issue 180016: Extension API Renaming/Consistency changes (Closed)
Patch Set: render docs Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_writer.h" 7 #include "base/json_writer.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/profile.h" 10 #include "chrome/browser/profile.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 initialized_ = true; 112 initialized_ = true;
113 } 113 }
114 114
115 ExtensionBrowserEventRouter::ExtensionBrowserEventRouter() 115 ExtensionBrowserEventRouter::ExtensionBrowserEventRouter()
116 : initialized_(false) { } 116 : initialized_(false) { }
117 117
118 void ExtensionBrowserEventRouter::OnBrowserAdded(const Browser* browser) { 118 void ExtensionBrowserEventRouter::OnBrowserAdded(const Browser* browser) {
119 // Start listening to TabStripModel events for this browser. 119 // Start listening to TabStripModel events for this browser.
120 browser->tabstrip_model()->AddObserver(this); 120 browser->tabstrip_model()->AddObserver(this);
121 121
122 DispatchSimpleBrowserEvent(browser->profile(), 122 ListValue args;
123 ExtensionTabUtil::GetWindowId(browser), 123 // TODO(rafaelw): This would ideally be returning a full Window object
124 events::kOnWindowCreated); 124 // via ExtensionTabUtil::CreateWindowValue(), but the browser->window()
125 // isn't ready at the time we get the OnBrowserAdded event.
126 DictionaryValue* window_dictionary = new DictionaryValue();
127 window_dictionary->SetInteger(extension_tabs_module_constants::kIdKey,
128 ExtensionTabUtil::GetWindowId(browser));
129 args.Append(window_dictionary);
130
131 std::string json_args;
132 JSONWriter::Write(&args, false, &json_args);
133
134 DispatchEvent(browser->profile(), events::kOnWindowCreated, json_args);
125 } 135 }
126 136
127 void ExtensionBrowserEventRouter::OnBrowserRemoving(const Browser* browser) { 137 void ExtensionBrowserEventRouter::OnBrowserRemoving(const Browser* browser) {
128 // Stop listening to TabStripModel events for this browser. 138 // Stop listening to TabStripModel events for this browser.
129 browser->tabstrip_model()->RemoveObserver(this); 139 browser->tabstrip_model()->RemoveObserver(this);
130 140
131 DispatchSimpleBrowserEvent(browser->profile(), 141 DispatchSimpleBrowserEvent(browser->profile(),
132 ExtensionTabUtil::GetWindowId(browser), 142 ExtensionTabUtil::GetWindowId(browser),
133 events::kOnWindowRemoved); 143 events::kOnWindowRemoved);
134 } 144 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 340
331 void ExtensionBrowserEventRouter::TabStripEmpty() { } 341 void ExtensionBrowserEventRouter::TabStripEmpty() { }
332 342
333 void ExtensionBrowserEventRouter::PageActionExecuted( 343 void ExtensionBrowserEventRouter::PageActionExecuted(
334 Profile* profile, 344 Profile* profile,
335 const std::string& extension_id, 345 const std::string& extension_id,
336 const std::string& page_action_id, 346 const std::string& page_action_id,
337 int tab_id, 347 int tab_id,
338 const std::string& url) { 348 const std::string& url) {
339 ListValue args; 349 ListValue args;
340 DictionaryValue* object_args = new DictionaryValue(); 350
341 object_args->Set(tab_keys::kPageActionIdKey, 351 args.Append(Value::CreateStringValue(page_action_id));
342 Value::CreateStringValue(page_action_id)); 352
343 DictionaryValue* data = new DictionaryValue(); 353 DictionaryValue* data = new DictionaryValue();
344 data->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); 354 data->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id));
345 data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url)); 355 data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url));
346 object_args->Set(tab_keys::kDataKey, data);
347 356
348 args.Append(object_args); 357 args.Append(data);
349 358
350 std::string json_args; 359 std::string json_args;
351 JSONWriter::Write(&args, false, &json_args); 360 JSONWriter::Write(&args, false, &json_args);
352 361
353 std::string event_name = extension_id + std::string("/") + page_action_id; 362 std::string event_name = extension_id + std::string("/") + page_action_id;
354 DispatchEvent(profile, event_name.c_str(), json_args); 363 DispatchEvent(profile, event_name.c_str(), json_args);
355 } 364 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698