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. 4 5 #ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_ 6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_ 7 8 #include <map> 9 #include <vector> 10 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" 18 19 class GURL; 20 class SkBitmap; 21 struct ExtensionMsg_ExecuteCode_Params; 22 struct ExtensionMsg_ExternalConnectionInfo; 23 struct WebApplicationInfo; 24 25 namespace base { 26 class DictionaryValue; 27 class ListValue; 28 } 29 30 namespace extensions { 31 class Dispatcher; 32 struct Message; 33 34 // RenderView-level plumbing for extension features. 35 class ExtensionHelper 36 : public content::RenderViewObserver, 37 public content::RenderViewObserverTracker<ExtensionHelper> { 38 public: 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, 45 ViewType view_type); 46 47 // Returns the given extension's background page, or NULL if none. 48 static content::RenderView* GetBackgroundPage( 49 const std::string& extension_id); 50 51 ExtensionHelper(content::RenderView* render_view, Dispatcher* dispatcher); 52 virtual ~ExtensionHelper(); 53 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_; } 58 59 private: 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) 71 OVERRIDE; 72 virtual void DidCreateDataSource(blink::WebFrame* frame, 73 blink::WebDataSource* ds) OVERRIDE; 74 virtual void DraggableRegionsChanged(blink::WebFrame* frame) OVERRIDE; 75 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, 83 bool user_gesture); 84 void OnExtensionDispatchOnConnect( 85 int target_port_id, 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(); 102 103 Dispatcher* dispatcher_; 104 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_; 109 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_; 113 114 // Type of view attached with RenderView. 115 ViewType view_type_; 116 117 // Id of the tab which the RenderView is attached to. 118 int tab_id_; 119 120 // Id number of browser window which RenderView is attached to. 121 int browser_window_id_; 122 123 DISALLOW_COPY_AND_ASSIGN(ExtensionHelper); 124 }; 125 126 } // namespace extensions 127 128 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_ 129