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 CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_CONTENTS_OBSERVER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_CONTENTS_OBSERVER_H_
8 #include "base/basictypes.h"
9 #include "base/strings/string16.h"
10 #include "content/public/browser/web_contents_observer.h"
11 #include "content/public/browser/web_contents_user_data.h"
12 #include "extensions/common/stack_frame.h"
18 namespace extensions
{
22 // A web contents observer that's used for WebContents in renderer and extension
23 // processes. Grants the renderer access to certain URL patterns for extensions,
24 // notifies the renderer that the extension was loaded and routes messages to
25 // the MessageService.
26 class ExtensionWebContentsObserver
27 : public content::WebContentsObserver
,
28 public content::WebContentsUserData
<ExtensionWebContentsObserver
> {
30 virtual ~ExtensionWebContentsObserver();
33 explicit ExtensionWebContentsObserver(content::WebContents
* web_contents
);
34 friend class content::WebContentsUserData
<ExtensionWebContentsObserver
>;
36 // content::WebContentsObserver overrides.
37 virtual void RenderViewCreated(
38 content::RenderViewHost
* render_view_host
) OVERRIDE
;
39 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
41 void OnPostMessage(int port_id
, const Message
& message
);
42 void OnDetailedConsoleMessageAdded(const base::string16
& message
,
43 const base::string16
& source
,
44 const StackTrace
& stack_trace
,
45 int32 severity_level
);
48 // Gets the extension or app (if any) that is associated with a RVH.
49 const Extension
* GetExtension(content::RenderViewHost
* render_view_host
);
51 // The browser context for the web contents this is observing.
52 content::BrowserContext
* browser_context_
;
54 DISALLOW_COPY_AND_ASSIGN(ExtensionWebContentsObserver
);
57 } // namespace extensions
59 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_CONTENTS_OBSERVER_H_