1 // Copyright (c) 2012 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 CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_
6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_
11 #include "base/memory/linked_ptr.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/public/common/console_message_level.h"
14 #include "content/public/renderer/render_view_observer.h"
15 #include "content/public/renderer/render_view_observer_tracker.h"
16 #include "extensions/common/view_type.h"
17 #include "third_party/WebKit/public/platform/WebURLResponse.h"
21 struct ExtensionMsg_ExecuteCode_Params
;
22 struct ExtensionMsg_ExternalConnectionInfo
;
23 struct WebApplicationInfo
;
26 class DictionaryValue
;
30 namespace extensions
{
34 // RenderView-level plumbing for extension features.
36 : public content::RenderViewObserver
,
37 public content::RenderViewObserverTracker
<ExtensionHelper
> {
39 // Returns a list of extension RenderViews that match the given filter
40 // criteria. If |browser_window_id| is not extension_misc::kUnknownWindowId,
41 // the list is restricted to views in that browser window.
42 static std::vector
<content::RenderView
*> GetExtensionViews(
43 const std::string
& extension_id
,
44 int browser_window_id
,
47 // Returns the given extension's background page, or NULL if none.
48 static content::RenderView
* GetBackgroundPage(
49 const std::string
& extension_id
);
51 ExtensionHelper(content::RenderView
* render_view
, Dispatcher
* dispatcher
);
52 virtual ~ExtensionHelper();
54 int tab_id() const { return tab_id_
; }
55 int browser_window_id() const { return browser_window_id_
; }
56 ViewType
view_type() const { return view_type_
; }
57 Dispatcher
* dispatcher() const { return dispatcher_
; }
60 // RenderViewObserver implementation.
61 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
62 virtual void DidFinishDocumentLoad(blink::WebFrame
* frame
) OVERRIDE
;
63 virtual void DidFinishLoad(blink::WebFrame
* frame
) OVERRIDE
;
64 virtual void DidCreateDocumentElement(blink::WebFrame
* frame
) OVERRIDE
;
65 virtual void DidStartProvisionalLoad(blink::WebFrame
* frame
) OVERRIDE
;
66 virtual void FrameDetached(blink::WebFrame
* frame
) OVERRIDE
;
67 virtual void DidMatchCSS(
68 blink::WebFrame
* frame
,
69 const blink::WebVector
<blink::WebString
>& newly_matching_selectors
,
70 const blink::WebVector
<blink::WebString
>& stopped_matching_selectors
)
72 virtual void DidCreateDataSource(blink::WebFrame
* frame
,
73 blink::WebDataSource
* ds
) OVERRIDE
;
74 virtual void DraggableRegionsChanged(blink::WebFrame
* frame
) OVERRIDE
;
76 void OnExtensionResponse(int request_id
, bool success
,
77 const base::ListValue
& response
,
78 const std::string
& error
);
79 void OnExtensionMessageInvoke(const std::string
& extension_id
,
80 const std::string
& module_name
,
81 const std::string
& function_name
,
82 const base::ListValue
& args
,
84 void OnExtensionDispatchOnConnect(
86 const std::string
& channel_name
,
87 const base::DictionaryValue
& source_tab
,
88 const ExtensionMsg_ExternalConnectionInfo
& info
,
89 const std::string
& tls_channel_id
);
90 void OnExtensionDeliverMessage(int target_port_id
,
91 const Message
& message
);
92 void OnExtensionDispatchOnDisconnect(int port_id
,
93 const std::string
& error_message
);
94 void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params
& params
);
95 void OnGetApplicationInfo(int page_id
);
96 void OnNotifyRendererViewType(ViewType view_type
);
97 void OnSetTabId(int tab_id
);
98 void OnUpdateBrowserWindowId(int window_id
);
99 void OnAddMessageToConsole(content::ConsoleMessageLevel level
,
100 const std::string
& message
);
101 void OnAppWindowClosed();
103 Dispatcher
* dispatcher_
;
105 // The app info that we are processing. This is used when installing an app
106 // via application definition. The in-progress web app is stored here while
107 // its manifest and icons are downloaded.
108 scoped_ptr
<WebApplicationInfo
> pending_app_info_
;
110 // The number of app icon requests outstanding. When this reaches zero, we're
111 // done processing an app definition file.
112 int pending_app_icon_requests_
;
114 // Type of view attached with RenderView.
117 // Id of the tab which the RenderView is attached to.
120 // Id number of browser window which RenderView is attached to.
121 int browser_window_id_
;
123 DISALLOW_COPY_AND_ASSIGN(ExtensionHelper
);
126 } // namespace extensions
128 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_