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

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: Vend frameIds at 1 location; minimize thread hops for webRequest 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
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 (process_id, routing_id) pair that
37 // identifies a RenderFrame to an extension frame ID.
nasko 2015/12/09 23:06:09 nit: s/identifies/maps/? Also RenderFrameHost to b
robwu 2015/12/10 00:00:51 Done.
38 class ExtensionApiFrameIdMap {
39 public:
40 typedef base::Callback<void(const ExtensionApiFrameId&)> FrameIdCallback;
41
42 // Runs |callback| with the result of calling GetFrameIdOnUI(). If the result
43 // was cached, the callback is immediately run. Otherwise the callback is
44 // queued and run in order when the result becomes available.
45 // Queued callbacks are not called when the class is destroyed.
46 // Can only be called on the IO thread.
47 static void GetFrameIdOnIO(int process_id,
48 int routing_id,
nasko 2015/12/09 23:06:10 nit: frame_routing_id or render_frame_routing_id
robwu 2015/12/10 00:00:51 Done.
49 FrameIdCallback callback);
50
51 // Get the frameId for a RenderFrameHost identified by |process_id| and
52 // |routing_id|. These methods always returns the same value when called with
53 // the same parameters.
54 // Can only be called on the UI thread.
55 static const ExtensionApiFrameId& GetFrameId(int process_id, int routing_id);
56 static const ExtensionApiFrameId& GetFrameId(content::RenderFrameHost* rfh);
57
58 // Find a RenderFrameHost for a given extension frame ID and WebContents.
59 // Returns nullptr if not found.
60 static content::RenderFrameHost* GetRenderFrameHostById(
61 int frame_id,
62 content::WebContents* web_contents);
nasko 2015/12/09 23:06:09 WebContents should be the first parameter, as it i
robwu 2015/12/10 00:00:51 Done.
63 };
64
65 } // namespace extensions
66
67 #endif // EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698