Roll WebRTC 7546:7549.
[chromium-blink-merge.git] / content / renderer / web_ui_mojo.h
blobdd9e752b238670ae4853a58c77f160fff0ec5083
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.
5 #ifndef CONTENT_RENDERER_WEB_UI_MOJO_H_
6 #define CONTENT_RENDERER_WEB_UI_MOJO_H_
8 #include <string>
10 #include "content/public/renderer/render_frame_observer.h"
11 #include "content/public/renderer/render_view_observer.h"
12 #include "content/public/renderer/render_view_observer_tracker.h"
13 #include "mojo/public/cpp/system/core.h"
15 namespace gin {
16 class PerContextData;
19 namespace content {
21 class WebUIMojoContextState;
23 // WebUIMojo is responsible for enabling the renderer side of mojo bindings.
24 // It creates (and destroys) a WebUIMojoContextState at the appropriate times
25 // and handles the necessary browser messages. WebUIMojo destroys itself when
26 // the RendererView it is created with is destroyed.
27 class WebUIMojo
28 : public RenderViewObserver,
29 public RenderViewObserverTracker<WebUIMojo> {
30 public:
31 explicit WebUIMojo(RenderView* render_view);
33 private:
34 class MainFrameObserver : public RenderFrameObserver {
35 public:
36 explicit MainFrameObserver(WebUIMojo* web_ui_mojo);
37 ~MainFrameObserver() override;
39 // RenderFrameObserver overrides:
40 void WillReleaseScriptContext(v8::Handle<v8::Context> context,
41 int world_id) override;
42 void DidFinishDocumentLoad() override;
44 private:
45 WebUIMojo* web_ui_mojo_;
47 DISALLOW_COPY_AND_ASSIGN(MainFrameObserver);
50 ~WebUIMojo() override;
52 void CreateContextState();
53 void DestroyContextState(v8::Handle<v8::Context> context);
55 // Invoked when the frame finishes loading. Invokes Run() on the
56 // WebUIMojoContextState.
57 void OnDidFinishDocumentLoad();
59 WebUIMojoContextState* GetContextState();
61 // RenderViewObserver overrides:
62 void DidCreateDocumentElement(blink::WebLocalFrame* frame) override;
63 void DidClearWindowObject(blink::WebLocalFrame* frame) override;
65 MainFrameObserver main_frame_observer_;
67 DISALLOW_COPY_AND_ASSIGN(WebUIMojo);
70 } // namespace content
72 #endif // CONTENT_RENDERER_WEB_UI_MOJO_H_