summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-30 00:48:51 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-30 00:48:51 +0000
commitc01639b7d1dfe57d3242cb26b1169e6c7ba8f797 (patch)
tree1d9e926ccc281d5e816642b0c8ca7f3c8343757a /chrome/browser
parent9e91e12a3f7a9629245cc8f37547531d3a98b1f2 (diff)
downloadchromium_src-c01639b7d1dfe57d3242cb26b1169e6c7ba8f797.zip
chromium_src-c01639b7d1dfe57d3242cb26b1169e6c7ba8f797.tar.gz
chromium_src-c01639b7d1dfe57d3242cb26b1169e6c7ba8f797.tar.bz2
Implement removeWindow, onWindowCreated, onWindowRemoved.
BUG=11200 R=aa Review URL: http://codereview.chromium.org/100164 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14924 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.cc28
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.h4
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc1
-rw-r--r--chrome/browser/extensions/extension_tabs_module.cc42
-rw-r--r--chrome/browser/extensions/extension_tabs_module.h3
5 files changed, 74 insertions, 4 deletions
diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc
index cefef15..c05e793 100644
--- a/chrome/browser/extensions/extension_browser_event_router.cc
+++ b/chrome/browser/extensions/extension_browser_event_router.cc
@@ -13,6 +13,8 @@
#include "chrome/browser/extensions/extension_tabs_module.h"
#include "chrome/common/notification_service.h"
+const char* kOnWindowCreated = "window-created";
+const char* kOnWindowRemoved = "window-removed";
const char* kOnTabCreated = "tab-created";
const char* kOnTabMoved = "tab-moved";
const char* kOnTabSelectionChanged = "tab-selection-changed";
@@ -55,10 +57,12 @@ void ExtensionBrowserEventRouter::Observe(NotificationType type,
case(NotificationType::BROWSER_OPENED) :
browser = Source<Browser>(source).ptr();
browser->tabstrip_model()->AddObserver(this);
+ BrowserOpened(browser);
break;
case(NotificationType::BROWSER_CLOSED) :
browser = Source<Browser>(source).ptr();
browser->tabstrip_model()->RemoveObserver(this);
+ BrowserClosed(browser);
break;
default:
NOTREACHED();
@@ -66,6 +70,30 @@ void ExtensionBrowserEventRouter::Observe(NotificationType type,
}
}
+void ExtensionBrowserEventRouter::BrowserOpened(Browser* browser) {
+ int window_id = ExtensionTabUtil::GetWindowId(browser);
+
+ ListValue args;
+ args.Append(Value::CreateIntegerValue(window_id));
+
+ std::string json_args;
+ JSONWriter::Write(&args, false, &json_args);
+
+ DispatchEvent(browser->profile(), kOnWindowCreated, json_args);
+}
+
+void ExtensionBrowserEventRouter::BrowserClosed(Browser* browser) {
+ int window_id = ExtensionTabUtil::GetWindowId(browser);
+
+ ListValue args;
+ args.Append(Value::CreateIntegerValue(window_id));
+
+ std::string json_args;
+ JSONWriter::Write(&args, false, &json_args);
+
+ DispatchEvent(browser->profile(), kOnWindowRemoved, json_args);
+}
+
void ExtensionBrowserEventRouter::TabInsertedAt(TabContents* contents,
int index,
bool foreground) {
diff --git a/chrome/browser/extensions/extension_browser_event_router.h b/chrome/browser/extensions/extension_browser_event_router.h
index 3a2f5ec..29ec398 100644
--- a/chrome/browser/extensions/extension_browser_event_router.h
+++ b/chrome/browser/extensions/extension_browser_event_router.h
@@ -45,6 +45,10 @@ class ExtensionBrowserEventRouter : public TabStripModelObserver,
const NotificationSource& source,
const NotificationDetails& details);
private:
+ // Construct and dispatch windows.onCreated event.
+ void BrowserOpened(Browser* browser);
+ // Construct and dispatch windows.onRemoved event.
+ void BrowserClosed(Browser* browser);
ExtensionBrowserEventRouter();
friend struct DefaultSingletonTraits<ExtensionBrowserEventRouter>;
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index 7e6099f..0d45d84 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -53,6 +53,7 @@ FactoryRegistry::FactoryRegistry() {
// Tabs
factories_["GetWindows"] = &NewExtensionFunction<GetWindowsFunction>;
factories_["CreateWindow"] = &NewExtensionFunction<CreateWindowFunction>;
+ factories_["RemoveWindow"] = &NewExtensionFunction<RemoveWindowFunction>;
factories_["GetTabsForWindow"] =
&NewExtensionFunction<GetTabsForWindowFunction>;
factories_["GetTab"] = &NewExtensionFunction<GetTabFunction>;
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index 67f4cc6..269ffce 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -70,10 +70,13 @@ bool GetWindowsFunction::RunImpl() {
result_.reset(new ListValue());
for (BrowserList::const_iterator browser = BrowserList::begin();
browser != BrowserList::end(); ++browser) {
- if (all_windows || (window_ids.find(ExtensionTabUtil::GetWindowId(*browser))
- != window_ids.end())) {
- static_cast<ListValue*>(result_.get())->Append(
+ // Only examine browsers in the current profile.
+ if ((*browser)->profile() == profile()) {
+ if (all_windows || (window_ids.find(ExtensionTabUtil::
+ GetWindowId(*browser)) != window_ids.end())) {
+ static_cast<ListValue*>(result_.get())->Append(
CreateWindowValue(*browser));
+ }
}
}
@@ -146,11 +149,42 @@ bool CreateWindowFunction::RunImpl() {
return true;
}
+bool RemoveWindowFunction::RunImpl() {
+ if (!args_->IsType(Value::TYPE_INTEGER))
+ return false;
+
+ int window_id;
+ if (!args_->GetAsInteger(&window_id))
+ return false;
+
+ Browser* target = NULL;
+ for (BrowserList::const_iterator browser = BrowserList::begin();
+ browser != BrowserList::end(); ++browser) {
+ // Only examine browsers in the current profile.
+ if ((*browser)->profile() == profile()) {
+ if (ExtensionTabUtil::GetWindowId(*browser) == window_id) {
+ target = *browser;
+ break;
+ }
+ }
+ }
+
+ if (target == NULL) {
+ // TODO(rafaelw): need error message.
+ return false;
+ }
+
+ target->CloseWindow();
+
+ return true;
+}
+
+
bool GetTabsForWindowFunction::RunImpl() {
if (!args_->IsType(Value::TYPE_NULL))
return false;
- Browser* browser = BrowserList::GetLastActive();
+ Browser* browser = dispatcher_->browser();
if (!browser)
return false;
diff --git a/chrome/browser/extensions/extension_tabs_module.h b/chrome/browser/extensions/extension_tabs_module.h
index 617fcf9..90c8647 100644
--- a/chrome/browser/extensions/extension_tabs_module.h
+++ b/chrome/browser/extensions/extension_tabs_module.h
@@ -23,6 +23,9 @@ class GetWindowsFunction : public SyncExtensionFunction {
class CreateWindowFunction : public SyncExtensionFunction {
virtual bool RunImpl();
};
+class RemoveWindowFunction : public SyncExtensionFunction {
+ virtual bool RunImpl();
+};
class GetTabsForWindowFunction : public SyncExtensionFunction {
virtual bool RunImpl();
};