OLD | NEW |
(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 (render_process_id, frame_routing_id) |
| 37 // pair that maps a RenderFrameHost to an extension frame ID. |
| 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 render_process_id, |
| 48 int frame_routing_id, |
| 49 FrameIdCallback callback); |
| 50 |
| 51 // Get the frameId for a RenderFrameHost identified by |render_process_id| and |
| 52 // |frame_routing_id|. These methods always returns the same value when called |
| 53 // with the same parameters. |
| 54 // Can only be called on the UI thread. |
| 55 static const ExtensionApiFrameId& GetFrameId(int render_process_id, |
| 56 int frame_routing_id); |
| 57 static const ExtensionApiFrameId& GetFrameId(content::RenderFrameHost* rfh); |
| 58 |
| 59 // Find a RenderFrameHost for a given extension frame ID and WebContents. |
| 60 // Returns nullptr if not found. |
| 61 static content::RenderFrameHost* GetRenderFrameHostById( |
| 62 content::WebContents* web_contents, |
| 63 int frame_id); |
| 64 }; |
| 65 |
| 66 } // namespace extensions |
| 67 |
| 68 #endif // EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_ |
OLD | NEW |