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

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: Add override specifier to destructor 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 chrome.* APIs 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.
Devlin 2015/12/12 14:25:00 it's probably superfluous with above, but let's be
robwu 2015/12/14 20:55:42 This is not what I meant, so I'll clarify it even
24 struct ExtensionApiFrameId {
25 static const int kInvalidFrameId = -1;
26
27 ExtensionApiFrameId();
28 explicit ExtensionApiFrameId(content::RenderFrameHost* rfh);
29
30 // The name "ExtensionApiFrameId" refers to |frame_id|.
31 int frame_id;
32
33 // The extension frame ID of the parent frame ID is also included because
34 // some extension APIs need both IDs.
35 int parent_frame_id;
36 };
37
38 // This class provides a mapping from a (render_process_id, frame_routing_id)
39 // pair that maps a RenderFrameHost to an extension frame ID.
40 class ExtensionApiFrameIdMap {
41 public:
42 using FrameIdCallback = base::Callback<void(const ExtensionApiFrameId&)>;
43
44 // Runs |callback| with the result that is equivalent to calling GetFrameId()
45 // on the UI thread. If the result was cached the callback is immediately run.
46 // Otherwise the callback is queued and run in order when the result becomes
47 // available. Queued callbacks are not called when the class is destroyed.
48 // Can only be called on the IO thread.
49 static void GetFrameIdOnIO(int render_process_id,
50 int frame_routing_id,
51 const FrameIdCallback& callback);
52
53 // Get the frameId for a RenderFrameHost identified by |render_process_id| and
54 // |frame_routing_id|. These methods always returns the same value when called
55 // with the same parameters.
56 // Can only be called on the UI thread.
57 static const ExtensionApiFrameId& GetFrameId(int render_process_id,
58 int frame_routing_id);
59 static const ExtensionApiFrameId& GetFrameId(content::RenderFrameHost* rfh);
60
61 // Find a RenderFrameHost for a given extension frame ID and WebContents.
62 // Returns nullptr if not found.
63 static content::RenderFrameHost* GetRenderFrameHostById(
64 content::WebContents* web_contents,
65 int frame_id);
66 };
67
68 } // namespace extensions
69
70 #endif // EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698