Index: extensions/browser/extension_api_frame_id_map.h |
diff --git a/extensions/browser/extension_api_frame_id_map.h b/extensions/browser/extension_api_frame_id_map.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9d6118626a714fb50082bf8aed2fcd2c82ff0cb5 |
--- /dev/null |
+++ b/extensions/browser/extension_api_frame_id_map.h |
@@ -0,0 +1,70 @@ |
+// Copyright 2015 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. |
+ |
+#ifndef EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_ |
+#define EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_ |
+ |
+#include "base/callback.h" |
+ |
+namespace content { |
+class RenderFrameHost; |
+class WebContents; |
+} // namespace content |
+ |
+namespace extensions { |
+ |
+// Extension frame IDs are exposed through the chrome.* APIs and have the |
+// following characteristics: |
+// - The top-level frame has ID 0. |
+// - Any child frame has a positive ID. |
+// - A non-existant frame has ID -1. |
+// - They are only guaranteed to be unique within a tab. |
+// - 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
|
+struct ExtensionApiFrameId { |
+ static const int kInvalidFrameId = -1; |
+ |
+ ExtensionApiFrameId(); |
+ explicit ExtensionApiFrameId(content::RenderFrameHost* rfh); |
+ |
+ // The name "ExtensionApiFrameId" refers to |frame_id|. |
+ int frame_id; |
+ |
+ // The extension frame ID of the parent frame ID is also included because |
+ // some extension APIs need both IDs. |
+ int parent_frame_id; |
+}; |
+ |
+// This class provides a mapping from a (render_process_id, frame_routing_id) |
+// pair that maps a RenderFrameHost to an extension frame ID. |
+class ExtensionApiFrameIdMap { |
+ public: |
+ using FrameIdCallback = base::Callback<void(const ExtensionApiFrameId&)>; |
+ |
+ // Runs |callback| with the result that is equivalent to calling GetFrameId() |
+ // on the UI thread. If the result was cached the callback is immediately run. |
+ // Otherwise the callback is queued and run in order when the result becomes |
+ // available. Queued callbacks are not called when the class is destroyed. |
+ // Can only be called on the IO thread. |
+ static void GetFrameIdOnIO(int render_process_id, |
+ int frame_routing_id, |
+ const FrameIdCallback& callback); |
+ |
+ // Get the frameId for a RenderFrameHost identified by |render_process_id| and |
+ // |frame_routing_id|. These methods always returns the same value when called |
+ // with the same parameters. |
+ // Can only be called on the UI thread. |
+ static const ExtensionApiFrameId& GetFrameId(int render_process_id, |
+ int frame_routing_id); |
+ static const ExtensionApiFrameId& GetFrameId(content::RenderFrameHost* rfh); |
+ |
+ // Find a RenderFrameHost for a given extension frame ID and WebContents. |
+ // Returns nullptr if not found. |
+ static content::RenderFrameHost* GetRenderFrameHostById( |
+ content::WebContents* web_contents, |
+ int frame_id); |
+}; |
+ |
+} // namespace extensions |
+ |
+#endif // EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_ |