Chromium Code Reviews| 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..3d2c69a3db524a5d63582cc81616b343c9f3d792 |
| --- /dev/null |
| +++ b/extensions/browser/extension_api_frame_id_map.h |
| @@ -0,0 +1,67 @@ |
| +// 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 (process_id, routing_id) pair that |
| +// identifies a RenderFrame to an extension frame ID. |
|
nasko
2015/12/09 23:06:09
nit: s/identifies/maps/? Also RenderFrameHost to b
robwu
2015/12/10 00:00:51
Done.
|
| +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 process_id, |
| + int routing_id, |
|
nasko
2015/12/09 23:06:10
nit: frame_routing_id or render_frame_routing_id
robwu
2015/12/10 00:00:51
Done.
|
| + FrameIdCallback callback); |
| + |
| + // Get the frameId for a RenderFrameHost identified by |process_id| and |
| + // |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 process_id, int 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( |
| + int frame_id, |
| + content::WebContents* web_contents); |
|
nasko
2015/12/09 23:06:09
WebContents should be the first parameter, as it i
robwu
2015/12/10 00:00:51
Done.
|
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_ |