diff options
author | rafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-22 00:32:52 +0000 |
---|---|---|
committer | rafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-22 00:32:52 +0000 |
commit | 14d8c66e0f2ab42aa3a0bf4f626140ba3a3a6d76 (patch) | |
tree | 70ae56de0ae927fe89e6beee96bb41977c06b401 | |
parent | 2d3c4998438e0de2d1e159023a79834e3a74e9e6 (diff) | |
download | chromium_src-14d8c66e0f2ab42aa3a0bf4f626140ba3a3a6d76.zip chromium_src-14d8c66e0f2ab42aa3a0bf4f626140ba3a3a6d76.tar.gz chromium_src-14d8c66e0f2ab42aa3a0bf4f626140ba3a3a6d76.tar.bz2 |
Add NotificationType::BROWSER_WINDOW_READY, chrome.windows.onCreated now sends full window
BUG=NONE
Review URL: http://codereview.chromium.org/195030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26771 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser.cc | 5 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_browser_event_router.cc | 21 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_browser_event_router.h | 4 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_uitest.cc | 3 | ||||
-rw-r--r-- | chrome/common/common_resources.grd | 2 | ||||
-rwxr-xr-x | chrome/common/extensions/api/extension_api.json | 8 | ||||
-rwxr-xr-x | chrome/common/extensions/docs/windows.html | 52 | ||||
-rw-r--r-- | chrome/common/notification_type.h | 17 | ||||
-rw-r--r-- | chrome/test/data/extensions/api_test/tabs/test.js | 32 | ||||
-rw-r--r-- | chrome/test/data/extensions/samples/tabs/tabs_api.html | 2 | ||||
-rw-r--r-- | chrome/test/data/extensions/uitest/event_sink/test.html | 2 |
11 files changed, 75 insertions, 73 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 1a037c5..4c36ab2 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -294,6 +294,11 @@ void Browser::CreateBrowserWindow() { window_ = BrowserWindow::CreateBrowserWindow(this); + NotificationService::current()->Notify( + NotificationType::BROWSER_WINDOW_READY, + Source<Browser>(this), + NotificationService::NoDetails()); + // Show the First Run information bubble if we've been told to. PrefService* local_state = g_browser_process->local_state(); if (!local_state) diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc index c1bce54..b20853e 100644 --- a/chrome/browser/extensions/extension_browser_event_router.cc +++ b/chrome/browser/extensions/extension_browser_event_router.cc @@ -121,13 +121,19 @@ void ExtensionBrowserEventRouter::OnBrowserAdded(const Browser* browser) { // Start listening to TabStripModel events for this browser. browser->tabstrip_model()->AddObserver(this); + // The window isn't ready at this point, so we defer until it is. + registrar_.Add(this, NotificationType::BROWSER_WINDOW_READY, + Source<const Browser>(browser)); +} + +void ExtensionBrowserEventRouter::OnBrowserWindowReady(const Browser* browser) { ListValue args; - // TODO(rafaelw): This would ideally be returning a full Window object - // via ExtensionTabUtil::CreateWindowValue(), but the browser->window() - // isn't ready at the time we get the OnBrowserAdded event. - DictionaryValue* window_dictionary = new DictionaryValue(); - window_dictionary->SetInteger(extension_tabs_module_constants::kIdKey, - ExtensionTabUtil::GetWindowId(browser)); + + registrar_.Remove(this, NotificationType::BROWSER_WINDOW_READY, + Source<const Browser>(browser)); + + DictionaryValue* window_dictionary = ExtensionTabUtil::CreateWindowValue( + browser, false); args.Append(window_dictionary); std::string json_args; @@ -329,6 +335,9 @@ void ExtensionBrowserEventRouter::Observe(NotificationType type, Source<NavigationController>(&contents->controller())); registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED, Source<TabContents>(contents)); + } else if (type == NotificationType::BROWSER_WINDOW_READY) { + const Browser* browser = Source<const Browser>(source).ptr(); + OnBrowserWindowReady(browser); } else { NOTREACHED(); } diff --git a/chrome/browser/extensions/extension_browser_event_router.h b/chrome/browser/extensions/extension_browser_event_router.h index c7aa3e9..fe3e9e7 100644 --- a/chrome/browser/extensions/extension_browser_event_router.h +++ b/chrome/browser/extensions/extension_browser_event_router.h @@ -35,6 +35,10 @@ class ExtensionBrowserEventRouter : public TabStripModelObserver, virtual void OnBrowserRemoving(const Browser* browser); virtual void OnBrowserSetLastActive(const Browser* browser); + // Called from Observe() on BROWSER_WINDOW_READY (not a part of + // BrowserList::Observer). + void OnBrowserWindowReady(const Browser* browser); + // TabStripModelObserver void TabInsertedAt(TabContents* contents, int index, bool foreground); void TabClosingAt(TabContents* contents, int index); diff --git a/chrome/browser/extensions/extension_uitest.cc b/chrome/browser/extensions/extension_uitest.cc index 0dcc28a..1f9238a 100644 --- a/chrome/browser/extensions/extension_uitest.cc +++ b/chrome/browser/extensions/extension_uitest.cc @@ -333,7 +333,8 @@ class BrowserEventAutomationProxy : public MultiMessageAutomationProxy { const char* BrowserEventAutomationProxy::events_[] = { // Window events. - "[\"windows.onCreated\", \"[{'id':42}]\"]", + "[\"windows.onCreated\", \"[{'id':42,'focused':true,'top':0,'left':0," + "'width':100,'height':100}]\"]", "[\"windows.onRemoved\", \"[42]\"]", diff --git a/chrome/common/common_resources.grd b/chrome/common/common_resources.grd index 5fc44f4..f7cb3ac 100644 --- a/chrome/common/common_resources.grd +++ b/chrome/common/common_resources.grd @@ -1,6 +1,4 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- This comment is only here because changes to resources are not picked up -without changes to the corresponding grd file. rw --> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="grit/common_resources.h" type="rc_header"> diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index 1d49a6c..f9c5883 100755 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -285,11 +285,9 @@ "description": "Fired when a window is created.", "parameters": [ { - "type": "object", - "name": "createInfo", - "properties": { - "id": {"type": "integer", "minimum": 0, "description": "ID of the new window."} - } + "$ref": "Window", + "name": "window", + "description": "Details of the window that was created." } ] }, diff --git a/chrome/common/extensions/docs/windows.html b/chrome/common/extensions/docs/windows.html index 19bfa72..9291dc5 100755 --- a/chrome/common/extensions/docs/windows.html +++ b/chrome/common/extensions/docs/windows.html @@ -1875,7 +1875,7 @@ the value of the current window falls back to the topmost window. <div class="summary"> <!-- Note: intentionally longer 80 columns --> - <span class="subdued">chrome.windows.</span><span>onCreated</span><span class="subdued">.addListener</span>(function(<span>object createInfo</span>) <span class="subdued">{...}</span>); + <span class="subdued">chrome.windows.</span><span>onCreated</span><span class="subdued">.addListener</span>(function(<span>Window window</span>) <span class="subdued">{...}</span>); </div> <div class="description"> @@ -1888,7 +1888,7 @@ the value of the current window falls back to the topmost window. <div jsinstance="*0"> <div> <dt> - <var>createInfo</var> + <var>window</var> <em> <!-- TYPE --> @@ -1896,50 +1896,14 @@ the value of the current window falls back to the topmost window. ( <span class="optional" style="display: none; ">optional</span> <span id="typeTemplate"> - <span style="display: none; "> - <a> Type</a> - </span> <span> - <span style="display: none; "> - array of <span><span></span></span> - </span> - <span>object</span> + <a href="windows.html#type-Window">Window</a> </span> - </span> - ) - </div> - - </em> - </dt> - <dd class="todo"> - Undocumented. - </dd> - <dd style="display: none; "> - Description of this parameter from the json schema. - </dd> - - <!-- OBJECT PROPERTIES --> - <dd> - <dl> - <div jsinstance="*0"> - <div> - <dt> - <var>id</var> - <em> - - <!-- TYPE --> - <div style="display:inline"> - ( - <span class="optional" style="display: none; ">optional</span> - <span id="typeTemplate"> <span style="display: none; "> - <a> Type</a> - </span> - <span> - <span style="display: none; "> + <span> array of <span><span></span></span> </span> - <span>integer</span> + <span>paramType</span> </span> </span> ) @@ -1950,7 +1914,7 @@ the value of the current window falls back to the topmost window. <dd class="todo" style="display: none; "> Undocumented. </dd> - <dd>ID of the new window.</dd> + <dd>Details of the window that was created.</dd> <!-- OBJECT PROPERTIES --> <dd style="display: none; "> @@ -1962,10 +1926,6 @@ the value of the current window falls back to the topmost window. </dl> </dd> </div> - </div> - </dl> - </dd> - </div> </div> </dl> diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index 72e0d13..a11fa49 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -182,16 +182,21 @@ class NotificationType { // Browser-window ---------------------------------------------------------- // This message is sent after a window has been opened. The source is a - // Source<Browser> with a pointer to the new window. No details are + // Source<Browser> containing the affected Browser. No details are // expected. BROWSER_OPENED, + // This message is sent soon after BROWSER_OPENED, and indicates that + // the Browser's |window_| is now non-NULL. The source is a Source<Browser> + // containing the affected Browser. No details are expected. + BROWSER_WINDOW_READY, + // This message is sent after a window has been closed. The source is a - // Source<Browser> with a pointer to the closed window. Details is a - // boolean that if true indicates that the application will be closed as a - // result of this browser window closure (i.e. this was the last opened - // browser window). Note that the boolean pointed to by Details is only - // valid for the duration of this call. + // Source<Browser> containing the affected Browser. Details is a boolean + // that if true indicates that the application will be closed as a result of + // this browser window closure (i.e. this was the last opened browser + // window). Note that the boolean pointed to by Details is only valid for + // the duration of this call. BROWSER_CLOSED, // This message is sent when the last window considered to be an diff --git a/chrome/test/data/extensions/api_test/tabs/test.js b/chrome/test/data/extensions/api_test/tabs/test.js index 867a34c..868877b 100644 --- a/chrome/test/data/extensions/api_test/tabs/test.js +++ b/chrome/test/data/extensions/api_test/tabs/test.js @@ -10,6 +10,7 @@ var testTabId = null; var moveWindow1 = null; var moveWindow2 = null; +var windowEventsWindow = null; var moveTabIds = {}; var pass = chrome.test.callbackPass; @@ -273,7 +274,7 @@ chrome.test.runTests([ })); }, */ - function onCreated() { + function tabsOnCreated() { chrome.test.listenOnce(chrome.tabs.onCreated, function(tab) { assertEq(pageUrl("f"), tab.url); }); @@ -282,7 +283,7 @@ chrome.test.runTests([ "selected": true}, pass(function(tab) {})); }, - function onUpdated() { + function tabsOnUpdated() { var onUpdatedCompleted = chrome.test.listenForever(chrome.tabs.onUpdated, function(tabid, info) { if (tabid == moveTabIds['a'] && info.status == "complete") { @@ -295,7 +296,7 @@ chrome.test.runTests([ pass()); }, - function onMoved() { + function tabsOnMoved() { chrome.test.listenOnce(chrome.tabs.onMoved, function(tabid, info) { assertEq(moveTabIds['a'], tabid); }); @@ -303,7 +304,7 @@ chrome.test.runTests([ chrome.tabs.move(moveTabIds['a'], {"index": 0}, pass()); }, - function onSelectionChanged() { + function tabsOnSelectionChanged() { chrome.test.listenOnce(chrome.tabs.onSelectionChanged, function(tabid, info) { assertEq(moveTabIds['c'], tabid); @@ -314,7 +315,7 @@ chrome.test.runTests([ pass()); }, - function onRemoved() { + function tabsOnRemoved() { chrome.test.listenOnce(chrome.tabs.onRemoved, function(tabid) { assertEq(moveTabIds['c'], tabid); }); @@ -366,6 +367,27 @@ chrome.test.runTests([ window.relativePageLoaded = chrome.test.callbackAdded(); chrome.windows.create({url: "relative.html"}); + }, + + function windowsOnCreated() { + chrome.test.listenOnce(chrome.windows.onCreated, function(window) { + chrome.test.assertTrue(window.width > 0); + chrome.test.assertTrue(window.height > 0); + windowEventsWindow = window; + chrome.tabs.getAllInWindow(window.id, pass(function(tabs) { + assertEq(pageUrl("a"), tabs[0].url); + })); + }); + + chrome.windows.create({"url": pageUrl("a")}, pass(function(tab) {})); + }, + + function windowsOnRemoved() { + chrome.test.listenOnce(chrome.windows.onRemoved, function(windowId) { + assertEq(windowEventsWindow.id, windowId); + }); + + chrome.windows.remove(windowEventsWindow.id, pass()); } // TODO(asargent) We still need to add tests for the following: diff --git a/chrome/test/data/extensions/samples/tabs/tabs_api.html b/chrome/test/data/extensions/samples/tabs/tabs_api.html index 9b9f519..4a784e3 100644 --- a/chrome/test/data/extensions/samples/tabs/tabs_api.html +++ b/chrome/test/data/extensions/samples/tabs/tabs_api.html @@ -156,7 +156,7 @@ chrome.windows.onRemoved.addListener(function(windowId) { }); chrome.tabs.onCreated.addListener(function(tab) { - appendToLog('tabs.onCreated -- window: ' + tab.windowId + ' tab: ' + tab.id + ' index ' + tab.index + ' url ' + tab.url); + appendToLog('tabs.onCreated -- window: ' + tab.windowId + ' tab: ' + tab.id + ' title: ' + tab.title + ' index ' + tab.index + ' url ' + tab.url); loadWindowList(); }); diff --git a/chrome/test/data/extensions/uitest/event_sink/test.html b/chrome/test/data/extensions/uitest/event_sink/test.html index 056f557..ecdd4fd 100644 --- a/chrome/test/data/extensions/uitest/event_sink/test.html +++ b/chrome/test/data/extensions/uitest/event_sink/test.html @@ -15,7 +15,7 @@ HOLA!!! If you dont see the message DONE, then there is an error in the script. }); // Window events. - chrome.windows.onCreated.addListener(function(createInfo) { + chrome.windows.onCreated.addListener(function(window) { portToAutomation.postMessage(chrome.windows.onCreated.eventName_); }); chrome.windows.onRemoved.addListener(function(windowId) { |