Assume the foo_test_run depends on everything needed to run the test.
[chromium-blink-merge.git] / content / renderer / web_ui_mojo.h
blob504f7373302994b022c8b8b969a707f0403f88e2
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 // Sets the handle to the current WebUI.
34 void SetBrowserHandle(mojo::ScopedMessagePipeHandle handle);
36 private:
37 class MainFrameObserver : public RenderFrameObserver {
38 public:
39 explicit MainFrameObserver(WebUIMojo* web_ui_mojo);
40 virtual ~MainFrameObserver();
42 // RenderFrameObserver overrides:
43 virtual void WillReleaseScriptContext(v8::Handle<v8::Context> context,
44 int world_id) OVERRIDE;
45 virtual void DidFinishDocumentLoad() OVERRIDE;
47 private:
48 WebUIMojo* web_ui_mojo_;
50 DISALLOW_COPY_AND_ASSIGN(MainFrameObserver);
53 virtual ~WebUIMojo();
55 void CreateContextState();
56 void DestroyContextState(v8::Handle<v8::Context> context);
58 // Invoked when the frame finishes loading. Invokes SetHandleOnContextState()
59 // if necessary.
60 void OnDidFinishDocumentLoad();
62 // Invokes SetHandle() on the WebUIMojoContextState (if there is one).
63 void SetHandleOnContextState(mojo::ScopedMessagePipeHandle handle);
65 WebUIMojoContextState* GetContextState();
67 // RenderViewObserver overrides:
68 virtual void DidClearWindowObject(blink::WebLocalFrame* frame,
69 int world_id) OVERRIDE;
71 MainFrameObserver main_frame_observer_;
73 // Set to true in DidFinishDocumentLoad(). 'main' is only executed once this
74 // happens.
75 bool did_finish_document_load_;
77 // If SetBrowserHandle() is invoked before the document finishes loading the
78 // MessagePipeHandle is stored here. When the document finishes loading
79 // SetHandleOnContextState() is invoked to send the handle to the
80 // WebUIMojoContextState and ultimately the page.
81 mojo::ScopedMessagePipeHandle pending_handle_;
83 DISALLOW_COPY_AND_ASSIGN(WebUIMojo);
86 } // namespace content
88 #endif // CONTENT_RENDERER_WEB_UI_MOJO_H_