1 // Copyright 2013 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.
5 #ifndef EXTENSIONS_RENDERER_EXTENSION_FRAME_HELPER_H_
6 #define EXTENSIONS_RENDERER_EXTENSION_FRAME_HELPER_H_
10 #include "content/public/common/console_message_level.h"
11 #include "content/public/renderer/render_frame_observer.h"
12 #include "content/public/renderer/render_frame_observer_tracker.h"
13 #include "extensions/common/view_type.h"
15 struct ExtensionMsg_ExternalConnectionInfo
;
16 struct ExtensionMsg_TabConnectionInfo
;
22 namespace extensions
{
28 // RenderFrame-level plumbing for extension features.
29 class ExtensionFrameHelper
30 : public content::RenderFrameObserver
,
31 public content::RenderFrameObserverTracker
<ExtensionFrameHelper
> {
33 ExtensionFrameHelper(content::RenderFrame
* render_frame
,
34 Dispatcher
* extension_dispatcher
);
35 ~ExtensionFrameHelper() override
;
37 // Returns a list of extension RenderFrames that match the given filter
38 // criteria. A |browser_window_id| of extension_misc::kUnknownWindowId
39 // specifies "all", as does a |view_type| of VIEW_TYPE_INVALID.
40 static std::vector
<content::RenderFrame
*> GetExtensionFrames(
41 const std::string
& extension_id
,
42 int browser_window_id
,
45 // Returns the main frame of the extension's background page, or null if there
46 // isn't one in this process.
47 static content::RenderFrame
* GetBackgroundPageFrame(
48 const std::string
& extension_id
);
50 // Returns true if the given |context| is for any frame in the extension's
52 // TODO(devlin): This isn't really used properly, and should probably be
54 static bool IsContextForEventPage(const ScriptContext
* context
);
56 ViewType
view_type() const { return view_type_
; }
57 int tab_id() const { return tab_id_
; }
58 int browser_window_id() const { return browser_window_id_
; }
59 const std::string
& tab_extension_owner_id() const {
60 return tab_extension_owner_id_
;
64 // RenderFrameObserver implementation.
65 void DidCreateDocumentElement() override
;
67 const blink::WebVector
<blink::WebString
>& newly_matching_selectors
,
68 const blink::WebVector
<blink::WebString
>& stopped_matching_selectors
)
70 void DidCreateScriptContext(v8::Local
<v8::Context
>,
72 int world_id
) override
;
73 void WillReleaseScriptContext(v8::Local
<v8::Context
>, int world_id
) override
;
74 bool OnMessageReceived(const IPC::Message
& message
) override
;
77 void OnExtensionDispatchOnConnect(
79 const std::string
& channel_name
,
80 const ExtensionMsg_TabConnectionInfo
& source
,
81 const ExtensionMsg_ExternalConnectionInfo
& info
,
82 const std::string
& tls_channel_id
);
83 void OnExtensionDeliverMessage(int target_port_id
,
84 const Message
& message
);
85 void OnExtensionDispatchOnDisconnect(int port_id
,
86 const std::string
& error_message
);
87 void OnExtensionSetTabId(int tab_id
);
88 void OnSetMainFrameExtensionOwner(const std::string
& extension_id
);
89 void OnUpdateBrowserWindowId(int browser_window_id
);
90 void OnNotifyRendererViewType(ViewType view_type
);
91 void OnExtensionResponse(int request_id
,
93 const base::ListValue
& response
,
94 const std::string
& error
);
95 void OnExtensionMessageInvoke(const std::string
& extension_id
,
96 const std::string
& module_name
,
97 const std::string
& function_name
,
98 const base::ListValue
& args
,
101 // Type of view associated with the RenderFrame.
104 // The id of the tab the render frame is attached to.
107 // The id of the browser window the render frame is attached to.
108 int browser_window_id_
;
110 // The id of the extension that "owns" the tab if this is a chrome-extension
111 // page. If it's not a chrome-extension page, |tab_extension_owner_id_| is
113 std::string tab_extension_owner_id_
;
115 Dispatcher
* extension_dispatcher_
;
117 DISALLOW_COPY_AND_ASSIGN(ExtensionFrameHelper
);
120 } // namespace extensions
122 #endif // EXTENSIONS_RENDERER_EXTENSION_FRAME_HELPER_H_