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

Unified Diff: chrome/browser/extensions/extension_toolstrip_api.cc

Issue 203023: add mole collapse/expand events. convert mappy to use this. (Closed)
Patch Set: add missing file 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_toolstrip_api.cc
diff --git a/chrome/browser/extensions/extension_toolstrip_api.cc b/chrome/browser/extensions/extension_toolstrip_api.cc
index 8f702430ed9d316e63e5b33bf446e90a52f04c8a..a502dcaa7196bc41cdd49153a3a43a9e5cd986a6 100644
--- a/chrome/browser/extensions/extension_toolstrip_api.cc
+++ b/chrome/browser/extensions/extension_toolstrip_api.cc
@@ -4,16 +4,24 @@
#include "chrome/browser/extensions/extension_toolstrip_api.h"
+#include "base/json_writer.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/extensions/extension_message_service.h"
#include "chrome/browser/extensions/extension_shelf_model.h"
#include "chrome/browser/extensions/extension_tabs_module_constants.h"
+#include "chrome/browser/profile.h"
namespace extension_toolstrip_api_functions {
const char kExpandFunction[] = "toolstrip.expand";
const char kCollapseFunction[] = "toolstrip.collapse";
}; // namespace extension_toolstrip_api_functions
+namespace extension_toolstrip_api_events {
+const char kOnToolstripExpanded[] = "toolstrip.onExpanded.%d";
+const char kOnToolstripCollapsed[] = "toolstrip.onCollapsed.%d";
+}; // namespace extension_toolstrip_api_events
+
namespace {
// Errors.
const char kNotAToolstripError[] = "This page is not a toolstrip.";
@@ -28,6 +36,7 @@ const int kMaxHeight = 1000;
}; // namespace
namespace keys = extension_tabs_module_constants;
+namespace events = extension_toolstrip_api_events;
bool ToolstripFunction::RunImpl() {
ExtensionHost* host = dispatcher()->GetExtensionHost();
@@ -119,3 +128,43 @@ bool ToolstripCollapseFunction::RunImpl() {
model_->CollapseToolstrip(toolstrip_, url);
return true;
}
+
+// static
+void ToolstripEventRouter::DispatchEvent(Profile *profile,
+ int routing_id,
+ const char *event_name,
+ const Value& json) {
+ if (profile->GetExtensionMessageService()) {
+ std::string json_args;
+ JSONWriter::Write(&json, false, &json_args);
+ std::string full_event_name = StringPrintf(event_name, routing_id);
+ profile->GetExtensionMessageService()->
+ DispatchEventToRenderers(full_event_name, json_args);
+ }
+}
+
+// static
+void ToolstripEventRouter::OnToolstripExpanded(Profile* profile,
+ int routing_id,
+ const GURL &url,
+ int height) {
+ ListValue args;
+ DictionaryValue* obj = new DictionaryValue();
+ if (!url.is_empty())
+ obj->SetString(keys::kUrlKey, url.spec());
+ obj->SetInteger(keys::kHeightKey, height);
+ args.Append(obj);
+ DispatchEvent(profile, routing_id, events::kOnToolstripExpanded, args);
+}
+
+// static
+void ToolstripEventRouter::OnToolstripCollapsed(Profile* profile,
+ int routing_id,
+ const GURL &url) {
+ ListValue args;
+ DictionaryValue* obj = new DictionaryValue();
+ if (!url.is_empty())
Matt Perry 2009/09/10 23:02:50 should we set the .url property to be "" rather th
+ obj->SetString(keys::kUrlKey, url.spec());
+ args.Append(obj);
+ DispatchEvent(profile, routing_id, events::kOnToolstripCollapsed, args);
+}
« no previous file with comments | « chrome/browser/extensions/extension_toolstrip_api.h ('k') | chrome/browser/extensions/extension_toolstrip_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698