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

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

Issue 159882: Implements extensions devtools API (Closed)
Patch Set: Fixes flakiness in tests by grabbing tab ID in C++ land and passing it down Created 11 years, 4 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_devtools_events.cc
diff --git a/chrome/browser/extensions/extension_devtools_events.cc b/chrome/browser/extensions/extension_devtools_events.cc
new file mode 100644
index 0000000000000000000000000000000000000000..979726cfa477b2c0fd52a4fecc72ddfa6c0aecfa
--- /dev/null
+++ b/chrome/browser/extensions/extension_devtools_events.cc
@@ -0,0 +1,60 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/extension_devtools_events.h"
+
+#include <vector>
+
+#include "base/string_util.h"
+
+// These string constants and the formats used in this file must stay
+// in sync with chrome/renderer/resources/extension_process_bindings.js
+static const char kDevToolsEventPrefix[] = "devtools.";
+static const char kOnPageEventName[] = "onPageEvent";
+static const char kOnTabUrlChangeEventName[] = "onTabUrlChange";
+static const char kOnTabCloseEventName[] = "onTabClose";
+
+// static
+bool ExtensionDevToolsEvents::IsDevToolsEventName(
+ const std::string& event_name, int* tab_id) {
+ // We only care about events of the form "devtools.34.*", where 34 is
+ // a tab id.
+ if (IsStringASCII(event_name) &&
+ StartsWithASCII(event_name,
+ kDevToolsEventPrefix,
+ true /* case_sensitive */)) {
+ // At this point we want something like "4.onPageEvent"
+ std::vector<std::string> parts;
+ SplitString(event_name.substr(strlen(kDevToolsEventPrefix)), '.', &parts);
+ if (parts.size() == 2 && StringToInt(parts[0], tab_id)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+// static
+std::string ExtensionDevToolsEvents::OnPageEventNameForTab(int tab_id) {
+ return StringPrintf("%s%d.%s",
+ kDevToolsEventPrefix,
+ tab_id,
+ kOnPageEventName);
+}
+
+// static
+std::string ExtensionDevToolsEvents::OnTabUrlChangeEventNameForTab(int tab_id) {
+ return StringPrintf("%s%d.%s",
+ kDevToolsEventPrefix,
+ tab_id,
+ kOnTabUrlChangeEventName);
+}
+
+// static
+std::string ExtensionDevToolsEvents::OnTabCloseEventNameForTab(int tab_id) {
+ return StringPrintf("%s%d.%s",
+ kDevToolsEventPrefix,
+ tab_id,
+ kOnTabCloseEventName);
+}
+
« no previous file with comments | « chrome/browser/extensions/extension_devtools_events.h ('k') | chrome/browser/extensions/extension_devtools_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698