Home | History | Annotate | Download | only in renderer
      1 // Copyright 2014 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 EXTENSIONS_RENDERER_EXTENSION_HELPER_H_
      6 #define EXTENSIONS_RENDERER_EXTENSION_HELPER_H_
      7 
      8 #include <vector>
      9 
     10 #include "content/public/common/console_message_level.h"
     11 #include "content/public/renderer/render_view_observer.h"
     12 #include "content/public/renderer/render_view_observer_tracker.h"
     13 #include "extensions/common/view_type.h"
     14 
     15 class GURL;
     16 class SkBitmap;
     17 struct ExtensionMsg_ExternalConnectionInfo;
     18 
     19 namespace base {
     20 class DictionaryValue;
     21 class ListValue;
     22 }
     23 
     24 namespace extensions {
     25 class Dispatcher;
     26 struct Message;
     27 
     28 // RenderView-level plumbing for extension features.
     29 class ExtensionHelper
     30     : public content::RenderViewObserver,
     31       public content::RenderViewObserverTracker<ExtensionHelper> {
     32  public:
     33   // Returns a list of extension RenderViews that match the given filter
     34   // criteria. If |browser_window_id| is not extension_misc::kUnknownWindowId,
     35   // the list is restricted to views in that browser window.
     36   static std::vector<content::RenderView*> GetExtensionViews(
     37       const std::string& extension_id,
     38       int browser_window_id,
     39       ViewType view_type);
     40 
     41   // Returns the given extension's background page, or NULL if none.
     42   static content::RenderView* GetBackgroundPage(
     43       const std::string& extension_id);
     44 
     45   ExtensionHelper(content::RenderView* render_view, Dispatcher* dispatcher);
     46   virtual ~ExtensionHelper();
     47 
     48   int tab_id() const { return tab_id_; }
     49   int browser_window_id() const { return browser_window_id_; }
     50   ViewType view_type() const { return view_type_; }
     51   Dispatcher* dispatcher() const { return dispatcher_; }
     52 
     53  private:
     54   // RenderViewObserver implementation.
     55   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     56   virtual void DidCreateDocumentElement(blink::WebLocalFrame* frame) OVERRIDE;
     57   virtual void DidMatchCSS(
     58       blink::WebLocalFrame* frame,
     59       const blink::WebVector<blink::WebString>& newly_matching_selectors,
     60       const blink::WebVector<blink::WebString>& stopped_matching_selectors)
     61       OVERRIDE;
     62   virtual void DraggableRegionsChanged(blink::WebFrame* frame) OVERRIDE;
     63 
     64   void OnExtensionResponse(int request_id, bool success,
     65                            const base::ListValue& response,
     66                            const std::string& error);
     67   void OnExtensionMessageInvoke(const std::string& extension_id,
     68                                 const std::string& module_name,
     69                                 const std::string& function_name,
     70                                 const base::ListValue& args,
     71                                 bool user_gesture);
     72   void OnExtensionDispatchOnConnect(
     73       int target_port_id,
     74       const std::string& channel_name,
     75       const base::DictionaryValue& source_tab,
     76       const ExtensionMsg_ExternalConnectionInfo& info,
     77       const std::string& tls_channel_id);
     78   void OnExtensionDeliverMessage(int target_port_id,
     79                                  const Message& message);
     80   void OnExtensionDispatchOnDisconnect(int port_id,
     81                                        const std::string& error_message);
     82   void OnNotifyRendererViewType(ViewType view_type);
     83   void OnSetTabId(int tab_id);
     84   void OnUpdateBrowserWindowId(int window_id);
     85   void OnAddMessageToConsole(content::ConsoleMessageLevel level,
     86                              const std::string& message);
     87   void OnAppWindowClosed();
     88   void OnSetFrameName(const std::string& name);
     89 
     90   Dispatcher* dispatcher_;
     91 
     92   // Type of view attached with RenderView.
     93   ViewType view_type_;
     94 
     95   // Id of the tab which the RenderView is attached to.
     96   int tab_id_;
     97 
     98   // Id number of browser window which RenderView is attached to.
     99   int browser_window_id_;
    100 
    101   DISALLOW_COPY_AND_ASSIGN(ExtensionHelper);
    102 };
    103 
    104 }  // namespace extensions
    105 
    106 #endif  // EXTENSIONS_RENDERER_EXTENSION_HELPER_H_
    107