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_CONTEXT_STATE_H_
6 #define CONTENT_RENDERER_WEB_UI_MOJO_CONTEXT_STATE_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "gin/modules/module_registry_observer.h"
14 #include "v8/include/v8.h"
28 class ResourceFetcher;
31 // WebUIMojoContextState manages the modules needed for mojo bindings. It does
32 // this by way of gin. Non-builtin modules are downloaded by way of
34 class WebUIMojoContextState : public gin::ModuleRegistryObserver {
36 WebUIMojoContextState(blink::WebFrame* frame,
37 v8::Handle<v8::Context> context);
38 ~WebUIMojoContextState() override;
42 // Returns true if at least one module was added.
43 bool module_added() const { return module_added_; }
48 // Invokes FetchModule() for any modules that have not already been
50 void FetchModules(const std::vector<std::string>& ids);
52 // Creates a ResourceFetcher to download |module|.
53 void FetchModule(const std::string& module);
55 // Callback once a module has finished downloading. Passes data to |runner_|.
56 void OnFetchModuleComplete(ResourceFetcher* fetcher,
57 const blink::WebURLResponse& response,
58 const std::string& data);
60 // gin::ModuleRegistryObserver overrides:
61 void OnDidAddPendingModule(
62 const std::string& id,
63 const std::vector<std::string>& dependencies) override;
65 // Frame script is executed in. Also used to download resources.
66 blink::WebFrame* frame_;
68 // See description above getter.
71 // Executes the script from gin.
72 scoped_ptr<WebUIRunner> runner_;
74 // Set of fetchers we're waiting on to download script.
75 ScopedVector<ResourceFetcher> module_fetchers_;
77 // Set of modules we've fetched script from.
78 std::set<std::string> fetched_modules_;
80 DISALLOW_COPY_AND_ASSIGN(WebUIMojoContextState);
83 } // namespace content
85 #endif // CONTENT_RENDERER_WEB_UI_MOJO_CONTEXT_STATE_H_