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

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

Issue 365513002: Port identity_internals to mojo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sky fixes Created 6 years, 4 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 #include "content/renderer/web_ui_mojo_context_state.h" 5 #include "content/renderer/web_ui_mojo_context_state.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "content/public/renderer/resource_fetcher.h" 9 #include "content/public/renderer/resource_fetcher.h"
10 #include "content/renderer/render_view_impl.h"
10 #include "content/renderer/web_ui_runner.h" 11 #include "content/renderer/web_ui_runner.h"
11 #include "gin/converter.h" 12 #include "gin/converter.h"
12 #include "gin/modules/module_registry.h" 13 #include "gin/modules/module_registry.h"
13 #include "gin/per_context_data.h" 14 #include "gin/per_context_data.h"
14 #include "gin/public/context_holder.h" 15 #include "gin/public/context_holder.h"
15 #include "gin/try_catch.h" 16 #include "gin/try_catch.h"
16 #include "mojo/bindings/js/core.h" 17 #include "mojo/bindings/js/core.h"
17 #include "mojo/bindings/js/handle.h" 18 #include "mojo/bindings/js/handle.h"
18 #include "mojo/bindings/js/support.h" 19 #include "mojo/bindings/js/support.h"
19 #include "third_party/WebKit/public/platform/WebURLResponse.h" 20 #include "third_party/WebKit/public/platform/WebURLResponse.h"
20 #include "third_party/WebKit/public/web/WebFrame.h" 21 #include "third_party/WebKit/public/web/WebFrame.h"
21 #include "third_party/WebKit/public/web/WebScriptSource.h" 22 #include "third_party/WebKit/public/web/WebScriptSource.h"
23 #include "third_party/WebKit/public/web/WebView.h"
22 24
23 using v8::Context; 25 using v8::Context;
24 using v8::HandleScope; 26 using v8::HandleScope;
25 using v8::Isolate; 27 using v8::Isolate;
26 using v8::Object; 28 using v8::Object;
27 using v8::ObjectTemplate; 29 using v8::ObjectTemplate;
28 using v8::Script; 30 using v8::Script;
29 31
30 namespace content { 32 namespace content {
31 33
32 namespace { 34 namespace {
33 35
34 // All modules have this prefixed to them when downloading. 36 // All modules have this prefixed to them when downloading.
35 // TODO(sky): move this into some common place. 37 // TODO(sky): move this into some common place.
36 const char kModulePrefix[] = "chrome://mojo/"; 38 const char kModulePrefix[] = "chrome://mojo/";
37 39
38 void RunMain(base::WeakPtr<gin::Runner> runner,
39 mojo::ScopedMessagePipeHandle* handle,
40 v8::Handle<v8::Value> module) {
41 v8::Isolate* isolate = runner->GetContextHolder()->isolate();
42 v8::Handle<v8::Function> start;
43 CHECK(gin::ConvertFromV8(isolate, module, &start));
44 v8::Handle<v8::Value> args[] = {
45 gin::ConvertToV8(isolate, mojo::Handle(handle->release().value())) };
46 runner->Call(start, runner->global(), 1, args);
47 }
48
49 } // namespace 40 } // namespace
50 41
51 // WebUIMojo ------------------------------------------------------------------- 42 // WebUIMojo -------------------------------------------------------------------
52 43
53 WebUIMojoContextState::WebUIMojoContextState(blink::WebFrame* frame, 44 WebUIMojoContextState::WebUIMojoContextState(RenderViewImpl* render_view,
54 v8::Handle<v8::Context> context) 45 v8::Handle<v8::Context> context)
55 : frame_(frame), 46 : frame_(render_view->GetWebView()->mainFrame()),
47 render_view_impl_(render_view),
56 module_added_(false) { 48 module_added_(false) {
57 gin::PerContextData* context_data = gin::PerContextData::From(context); 49 gin::PerContextData* context_data = gin::PerContextData::From(context);
58 gin::ContextHolder* context_holder = context_data->context_holder(); 50 gin::ContextHolder* context_holder = context_data->context_holder();
59 runner_.reset(new WebUIRunner(frame_, context_holder)); 51 runner_.reset(new WebUIRunner(frame_, context_holder));
60 gin::Runner::Scope scoper(runner_.get()); 52 gin::Runner::Scope scoper(runner_.get());
61 gin::ModuleRegistry::From(context)->AddObserver(this); 53 gin::ModuleRegistry::From(context)->AddObserver(this);
62 runner_->RegisterBuiltinModules(); 54 runner_->RegisterBuiltinModules();
63 gin::ModuleRegistry::InstallGlobals(context->GetIsolate(), context->Global()); 55 gin::ModuleRegistry::InstallGlobals(context->GetIsolate(), context->Global());
64 // Warning |frame| may be destroyed. 56 // Warning |frame| may be destroyed.
65 // TODO(sky): add test for this. 57 // TODO(sky): add test for this.
66 } 58 }
67 59
68 WebUIMojoContextState::~WebUIMojoContextState() { 60 WebUIMojoContextState::~WebUIMojoContextState() {
69 gin::Runner::Scope scoper(runner_.get()); 61 gin::Runner::Scope scoper(runner_.get());
70 gin::ModuleRegistry::From( 62 gin::ModuleRegistry::From(
71 runner_->GetContextHolder()->context())->RemoveObserver(this); 63 runner_->GetContextHolder()->context())->RemoveObserver(this);
72 } 64 }
73 65
74 void WebUIMojoContextState::SetHandle(mojo::ScopedMessagePipeHandle handle) { 66 void WebUIMojoContextState::SetHandle(mojo::ScopedMessagePipeHandle handle) {
75 gin::ContextHolder* context_holder = runner_->GetContextHolder(); 67 gin::ContextHolder* context_holder = runner_->GetContextHolder();
76 mojo::ScopedMessagePipeHandle* passed_handle = 68 mojo::ScopedMessagePipeHandle* passed_handle =
77 new mojo::ScopedMessagePipeHandle(handle.Pass()); 69 new mojo::ScopedMessagePipeHandle(handle.Pass());
78 gin::ModuleRegistry::From(context_holder->context())->LoadModule( 70 gin::ModuleRegistry::From(context_holder->context())->LoadModule(
79 context_holder->isolate(), 71 context_holder->isolate(),
80 "main", 72 "main",
81 base::Bind(RunMain, runner_->GetWeakPtr(), base::Owned(passed_handle))); 73 base::Bind(&WebUIMojoContextState::RunMain,
74 AsWeakPtr(),
75 base::Owned(passed_handle)));
76 }
77
78 void WebUIMojoContextState::RunMain(mojo::ScopedMessagePipeHandle* handle,
79 v8::Handle<v8::Value> module) {
80 v8::Isolate* isolate = runner_->GetContextHolder()->isolate();
81 v8::Handle<v8::Function> start;
82 CHECK(gin::ConvertFromV8(isolate, module, &start));
83 v8::Handle<v8::Value> args[] = {
84 gin::ConvertToV8(isolate, mojo::Handle(handle->release().value())) };
85 runner_->Call(start, runner_->global(), 1, args);
86
87 render_view_impl_->WebUIMojoMainRan();
jam 2014/07/25 21:29:58 here, you can use frame_ to get to a RenderFrame,
82 } 88 }
83 89
84 void WebUIMojoContextState::FetchModules(const std::vector<std::string>& ids) { 90 void WebUIMojoContextState::FetchModules(const std::vector<std::string>& ids) {
85 gin::Runner::Scope scoper(runner_.get()); 91 gin::Runner::Scope scoper(runner_.get());
86 gin::ContextHolder* context_holder = runner_->GetContextHolder(); 92 gin::ContextHolder* context_holder = runner_->GetContextHolder();
87 gin::ModuleRegistry* registry = gin::ModuleRegistry::From( 93 gin::ModuleRegistry* registry = gin::ModuleRegistry::From(
88 context_holder->context()); 94 context_holder->context());
89 for (size_t i = 0; i < ids.size(); ++i) { 95 for (size_t i = 0; i < ids.size(); ++i) {
90 if (fetched_modules_.find(ids[i]) == fetched_modules_.end() && 96 if (fetched_modules_.find(ids[i]) == fetched_modules_.end() &&
91 registry->available_modules().count(ids[i]) == 0) { 97 registry->available_modules().count(ids[i]) == 0) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 const std::vector<std::string>& dependencies) { 139 const std::vector<std::string>& dependencies) {
134 FetchModules(dependencies); 140 FetchModules(dependencies);
135 141
136 gin::ContextHolder* context_holder = runner_->GetContextHolder(); 142 gin::ContextHolder* context_holder = runner_->GetContextHolder();
137 gin::ModuleRegistry* registry = gin::ModuleRegistry::From( 143 gin::ModuleRegistry* registry = gin::ModuleRegistry::From(
138 context_holder->context()); 144 context_holder->context());
139 registry->AttemptToLoadMoreModules(context_holder->isolate()); 145 registry->AttemptToLoadMoreModules(context_holder->isolate());
140 } 146 }
141 147
142 } // namespace content 148 } // namespace content
OLDNEW
« content/renderer/web_ui_mojo_context_state.h ('K') | « content/renderer/web_ui_mojo_context_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698