Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / extensions / renderer / extension_frame_helper.h
blobe6f542e18cd4561d4857c0869515814f3b7d85e7
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_
8 #include <vector>
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;
18 namespace base {
19 class ListValue;
22 namespace extensions {
24 class Dispatcher;
25 struct Message;
26 class ScriptContext;
28 // RenderFrame-level plumbing for extension features.
29 class ExtensionFrameHelper
30 : public content::RenderFrameObserver,
31 public content::RenderFrameObserverTracker<ExtensionFrameHelper> {
32 public:
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,
43 ViewType view_type);
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
51 // event page.
52 // TODO(devlin): This isn't really used properly, and should probably be
53 // deleted.
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 bool did_create_current_document_element() const {
60 return did_create_current_document_element_;
63 private:
64 // RenderFrameObserver implementation.
65 void DidCreateDocumentElement() override;
66 void DidCreateNewDocument() override;
67 void DidMatchCSS(
68 const blink::WebVector<blink::WebString>& newly_matching_selectors,
69 const blink::WebVector<blink::WebString>& stopped_matching_selectors)
70 override;
71 void DidCreateScriptContext(v8::Local<v8::Context>,
72 int extension_group,
73 int world_id) override;
74 void WillReleaseScriptContext(v8::Local<v8::Context>, int world_id) override;
75 bool OnMessageReceived(const IPC::Message& message) override;
77 // IPC handlers.
78 void OnExtensionDispatchOnConnect(
79 int target_port_id,
80 const std::string& channel_name,
81 const ExtensionMsg_TabConnectionInfo& source,
82 const ExtensionMsg_ExternalConnectionInfo& info,
83 const std::string& tls_channel_id);
84 void OnExtensionDeliverMessage(int target_port_id,
85 const Message& message);
86 void OnExtensionDispatchOnDisconnect(int port_id,
87 const std::string& error_message);
88 void OnExtensionSetTabId(int tab_id);
89 void OnUpdateBrowserWindowId(int browser_window_id);
90 void OnNotifyRendererViewType(ViewType view_type);
91 void OnExtensionResponse(int request_id,
92 bool success,
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,
99 bool user_gesture);
101 // Type of view associated with the RenderFrame.
102 ViewType view_type_;
104 // The id of the tab the render frame is attached to.
105 int tab_id_;
107 // The id of the browser window the render frame is attached to.
108 int browser_window_id_;
110 Dispatcher* extension_dispatcher_;
112 // Whether or not the current document element has been created.
113 bool did_create_current_document_element_;
115 DISALLOW_COPY_AND_ASSIGN(ExtensionFrameHelper);
118 } // namespace extensions
120 #endif // EXTENSIONS_RENDERER_EXTENSION_FRAME_HELPER_H_