| 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);
|
| +}
|
| +
|
|
|