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

Side by Side Diff: extensions/browser/extension_api_frame_id_map.h

Issue 1413543005: Use FrameTreeNode ID as frameId in extension APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years 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 2015 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 #ifndef EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_
7
8 #include "base/callback.h"
9
10 namespace content {
11 class RenderFrameHost;
12 class WebContents;
13 } // namespace content
14
15 namespace extensions {
16
17 // Extension frame IDs are exposed through the extension API and have the
Devlin 2015/12/10 21:53:07 "the extension API"? That sounds like chrome.exte
robwu 2015/12/11 00:53:48 Changed to "through the chrome.* APIs"
18 // following characteristics:
19 // - The top-level frame has ID 0.
20 // - Any child frame has a positive ID.
21 // - A non-existant frame has ID -1.
22 // - They are only guaranteed to be unique within a tab.
23 // - Multiple RenderFrameHosts may be mapped to the same ID.
24 struct ExtensionApiFrameId {
25 static const int kInvalidFrameId = -1;
26 ExtensionApiFrameId();
27
28 // The name "ExtensionApiFrameId" refers to |frame_id|.
29 int frame_id;
30
31 // The extension frame ID of the parent frame ID is also included because
32 // some extension APIs need both IDs.
33 int parent_frame_id;
34 };
35
36 // This class provides a mapping from a (render_process_id, frame_routing_id)
37 // pair that maps a RenderFrameHost to an extension frame ID.
38 class ExtensionApiFrameIdMap {
Devlin 2015/12/10 21:53:07 Does this class warrant a few small unit tests?
robwu 2015/12/11 00:53:48 The functionality is already covered by the consum
39 public:
40 typedef base::Callback<void(const ExtensionApiFrameId&)> FrameIdCallback;
Devlin 2015/12/10 21:53:07 nit: Prefer using.
robwu 2015/12/11 00:53:48 Done.
41
42 // Runs |callback| with the result that is equivalent to calling GetFrameId()
43 // on the UI thread. If the result was cached the callback is immediately run.
44 // Otherwise the callback is queued and run in order when the result becomes
45 // available. Queued callbacks are not called when the class is destroyed.
46 // Can only be called on the IO thread.
47 static void GetFrameIdOnIO(int render_process_id,
48 int frame_routing_id,
49 FrameIdCallback callback);
Devlin 2015/12/10 21:53:07 const &
robwu 2015/12/11 00:53:48 Done.
50
51 // Get the frameId for a RenderFrameHost identified by |render_process_id| and
52 // |frame_routing_id|. These methods always returns the same value when called
53 // with the same parameters.
54 // Can only be called on the UI thread.
55 static const ExtensionApiFrameId& GetFrameId(int render_process_id,
56 int frame_routing_id);
57 static const ExtensionApiFrameId& GetFrameId(content::RenderFrameHost* rfh);
58
59 // Find a RenderFrameHost for a given extension frame ID and WebContents.
60 // Returns nullptr if not found.
61 static content::RenderFrameHost* GetRenderFrameHostById(
62 content::WebContents* web_contents,
63 int frame_id);
64 };
65
66 } // namespace extensions
67
68 #endif // EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698