Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: content/renderer/web_ui_mojo_context_state.h

Issue 365513002: Port identity_internals to mojo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sky fixes Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_WEB_UI_MOJO_CONTEXT_STATE_H_ 5 #ifndef CONTENT_RENDERER_WEB_UI_MOJO_CONTEXT_STATE_H_
6 #define CONTENT_RENDERER_WEB_UI_MOJO_CONTEXT_STATE_H_ 6 #define CONTENT_RENDERER_WEB_UI_MOJO_CONTEXT_STATE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h"
13 #include "gin/modules/module_registry_observer.h" 14 #include "gin/modules/module_registry_observer.h"
14 #include "mojo/public/cpp/system/core.h" 15 #include "mojo/public/cpp/system/core.h"
15 #include "v8/include/v8.h" 16 #include "v8/include/v8.h"
16 17
17 namespace blink { 18 namespace blink {
18 class WebFrame; 19 class WebFrame;
19 class WebURLResponse; 20 class WebURLResponse;
20 } 21 }
21 22
22 namespace gin { 23 namespace gin {
23 class ContextHolder; 24 class ContextHolder;
25 class Runner;
24 struct PendingModule; 26 struct PendingModule;
25 } 27 }
26 28
27 namespace content { 29 namespace content {
28 30
31 class RenderViewImpl;
29 class ResourceFetcher; 32 class ResourceFetcher;
30 class WebUIRunner; 33 class WebUIRunner;
31 34
32 // WebUIMojoContextState manages the modules needed for mojo bindings. It does 35 // WebUIMojoContextState manages the modules needed for mojo bindings. It does
33 // this by way of gin. Non-builtin modules are downloaded by way of 36 // this by way of gin. Non-builtin modules are downloaded by way of
34 // ResourceFetchers. 37 // ResourceFetchers.
35 class WebUIMojoContextState : public gin::ModuleRegistryObserver { 38 class WebUIMojoContextState
39 : public gin::ModuleRegistryObserver,
40 public base::SupportsWeakPtr<WebUIMojoContextState> {
36 public: 41 public:
37 WebUIMojoContextState(blink::WebFrame* frame, 42 WebUIMojoContextState(RenderViewImpl* render_view,
jam 2014/07/25 21:29:58 leave as is
38 v8::Handle<v8::Context> context); 43 v8::Handle<v8::Context> context);
39 virtual ~WebUIMojoContextState(); 44 virtual ~WebUIMojoContextState();
40 45
41 // Called once the mojo::Handle is available. 46 // Called once the mojo::Handle is available.
42 void SetHandle(mojo::ScopedMessagePipeHandle handle); 47 void SetHandle(mojo::ScopedMessagePipeHandle handle);
43 48
44 // Returns true if at least one module was added. 49 // Returns true if at least one module was added.
45 bool module_added() const { return module_added_; } 50 bool module_added() const { return module_added_; }
46 51
47 private: 52 private:
48 class Loader; 53 class Loader;
49 54
55 // The implementation of the 'main' module. Calls the closure passed in and
56 // then notifies our RenderView that we've run the main closure.
57 void RunMain(mojo::ScopedMessagePipeHandle* handle,
58 v8::Handle<v8::Value> module);
59
50 // Invokes FetchModule() for any modules that have not already been 60 // Invokes FetchModule() for any modules that have not already been
51 // downloaded. 61 // downloaded.
52 void FetchModules(const std::vector<std::string>& ids); 62 void FetchModules(const std::vector<std::string>& ids);
53 63
54 // Creates a ResourceFetcher to download |module|. 64 // Creates a ResourceFetcher to download |module|.
55 void FetchModule(const std::string& module); 65 void FetchModule(const std::string& module);
56 66
57 // Callback once a module has finished downloading. Passes data to |runner_|. 67 // Callback once a module has finished downloading. Passes data to |runner_|.
58 void OnFetchModuleComplete(ResourceFetcher* fetcher, 68 void OnFetchModuleComplete(ResourceFetcher* fetcher,
59 const blink::WebURLResponse& response, 69 const blink::WebURLResponse& response,
60 const std::string& data); 70 const std::string& data);
61 71
62 // gin::ModuleRegistryObserver overrides: 72 // gin::ModuleRegistryObserver overrides:
63 virtual void OnDidAddPendingModule( 73 virtual void OnDidAddPendingModule(
64 const std::string& id, 74 const std::string& id,
65 const std::vector<std::string>& dependencies) OVERRIDE; 75 const std::vector<std::string>& dependencies) OVERRIDE;
66 76
67 // Frame script is executed in. Also used to download resources. 77 // Frame script is executed in. Also used to download resources.
68 blink::WebFrame* frame_; 78 blink::WebFrame* frame_;
69 79
80 // We keep the RenderViewImpl so we can send a message once the main callback
81 // has run.
82 RenderViewImpl* render_view_impl_;
83
70 // See description above getter. 84 // See description above getter.
71 bool module_added_; 85 bool module_added_;
72 86
73 // Executes the script from gin. 87 // Executes the script from gin.
74 scoped_ptr<WebUIRunner> runner_; 88 scoped_ptr<WebUIRunner> runner_;
75 89
76 // Set of fetchers we're waiting on to download script. 90 // Set of fetchers we're waiting on to download script.
77 ScopedVector<ResourceFetcher> module_fetchers_; 91 ScopedVector<ResourceFetcher> module_fetchers_;
78 92
79 // Set of modules we've fetched script from. 93 // Set of modules we've fetched script from.
80 std::set<std::string> fetched_modules_; 94 std::set<std::string> fetched_modules_;
81 95
82 DISALLOW_COPY_AND_ASSIGN(WebUIMojoContextState); 96 DISALLOW_COPY_AND_ASSIGN(WebUIMojoContextState);
83 }; 97 };
84 98
85 } // namespace content 99 } // namespace content
86 100
87 #endif // CONTENT_RENDERER_WEB_UI_MOJO_CONTEXT_STATE_H_ 101 #endif // CONTENT_RENDERER_WEB_UI_MOJO_CONTEXT_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698