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..bd1476c7128c8713d6e2f8a109bc0048432226a3 |
--- /dev/null |
+++ b/extensions/browser/extension_api_frame_id_map.h |
@@ -0,0 +1,68 @@ |
+// 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 extension API 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. |
+struct ExtensionApiFrameId { |
+ static const int kInvalidFrameId = -1; |
+ ExtensionApiFrameId(); |
+ |
+ // 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: |
+ typedef base::Callback<void(const ExtensionApiFrameId&)> FrameIdCallback; |
+ |
+ // Runs |callback| with the result of calling GetFrameIdOnUI(). 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, |
+ 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_ |