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

Unified 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: Charlie's nits (#33) 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 side-by-side diff with in-line comments
Download patch
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
battre 2015/12/10 15:31:39 nit: GetFrameIdOnUI() is not described here.
robwu 2015/12/10 16:39:30 Done.
+ // 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,
battre 2015/12/10 15:31:39 is it guaranteed that proccess ids are never reuse
robwu 2015/12/10 16:39:29 Yes, see RenderProcessHost::GetID.
+ 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_

Powered by Google App Engine
This is Rietveld 408576698