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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/extension_devtools_events.h"
6
7 #include <vector>
8
9 #include "base/string_util.h"
10
11 // These string constants and the formats used in this file must stay
12 // in sync with chrome/renderer/resources/extension_process_bindings.js
13 static const char kDevToolsEventPrefix[] = "devtools.";
14 static const char kOnPageEventName[] = "onPageEvent";
15 static const char kOnTabUrlChangeEventName[] = "onTabUrlChange";
16 static const char kOnTabCloseEventName[] = "onTabClose";
17
18 // static
19 bool ExtensionDevToolsEvents::IsDevToolsEventName(
20 const std::string& event_name, int* tab_id) {
21 // We only care about events of the form "devtools.34.*", where 34 is
22 // a tab id.
23 if (IsStringASCII(event_name) &&
24 StartsWithASCII(event_name,
25 kDevToolsEventPrefix,
26 true /* case_sensitive */)) {
27 // At this point we want something like "4.onPageEvent"
28 std::vector<std::string> parts;
29 SplitString(event_name.substr(strlen(kDevToolsEventPrefix)), '.', &parts);
30 if (parts.size() == 2 && StringToInt(parts[0], tab_id)) {
31 return true;
32 }
33 }
34 return false;
35 }
36
37 // static
38 std::string ExtensionDevToolsEvents::OnPageEventNameForTab(int tab_id) {
39 return StringPrintf("%s%d.%s",
40 kDevToolsEventPrefix,
41 tab_id,
42 kOnPageEventName);
43 }
44
45 // static
46 std::string ExtensionDevToolsEvents::OnTabUrlChangeEventNameForTab(int tab_id) {
47 return StringPrintf("%s%d.%s",
48 kDevToolsEventPrefix,
49 tab_id,
50 kOnTabUrlChangeEventName);
51 }
52
53 // static
54 std::string ExtensionDevToolsEvents::OnTabCloseEventNameForTab(int tab_id) {
55 return StringPrintf("%s%d.%s",
56 kDevToolsEventPrefix,
57 tab_id,
58 kOnTabCloseEventName);
59 }
60
OLDNEW
« 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