| OLD | NEW |
| 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/web_ui_runner.h" | 10 #include "content/renderer/web_ui_runner.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // All modules have this prefixed to them when downloading. | 33 // All modules have this prefixed to them when downloading. |
| 34 // TODO(sky): move this into some common place. | 34 // TODO(sky): move this into some common place. |
| 35 const char kModulePrefix[] = "chrome://mojo/"; | 35 const char kModulePrefix[] = "chrome://mojo/"; |
| 36 | 36 |
| 37 void RunMain(base::WeakPtr<gin::Runner> runner, | 37 void RunMain(base::WeakPtr<gin::Runner> runner, |
| 38 mojo::ScopedHandle* handle, | 38 mojo::ScopedMessagePipeHandle* handle, |
| 39 v8::Handle<v8::Value> module) { | 39 v8::Handle<v8::Value> module) { |
| 40 v8::Isolate* isolate = runner->GetContextHolder()->isolate(); | 40 v8::Isolate* isolate = runner->GetContextHolder()->isolate(); |
| 41 v8::Handle<v8::Function> start; | 41 v8::Handle<v8::Function> start; |
| 42 CHECK(gin::ConvertFromV8(isolate, module, &start)); | 42 CHECK(gin::ConvertFromV8(isolate, module, &start)); |
| 43 v8::Handle<v8::Value> args[] = { | 43 v8::Handle<v8::Value> args[] = { |
| 44 gin::ConvertToV8(isolate, handle->release().value()) }; | 44 gin::ConvertToV8(isolate, handle->release().value()) }; |
| 45 runner->Call(start, runner->global(), 1, args); | 45 runner->Call(start, runner->global(), 1, args); |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| (...skipping 14 matching lines...) Expand all Loading... |
| 63 // Warning |frame| may be destroyed. | 63 // Warning |frame| may be destroyed. |
| 64 // TODO(sky): add test for this. | 64 // TODO(sky): add test for this. |
| 65 } | 65 } |
| 66 | 66 |
| 67 WebUIMojoContextState::~WebUIMojoContextState() { | 67 WebUIMojoContextState::~WebUIMojoContextState() { |
| 68 gin::Runner::Scope scoper(runner_.get()); | 68 gin::Runner::Scope scoper(runner_.get()); |
| 69 gin::ModuleRegistry::From( | 69 gin::ModuleRegistry::From( |
| 70 runner_->GetContextHolder()->context())->RemoveObserver(this); | 70 runner_->GetContextHolder()->context())->RemoveObserver(this); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void WebUIMojoContextState::SetHandle(mojo::ScopedHandle handle) { | 73 void WebUIMojoContextState::SetHandle(mojo::ScopedMessagePipeHandle handle) { |
| 74 gin::ContextHolder* context_holder = runner_->GetContextHolder(); | 74 gin::ContextHolder* context_holder = runner_->GetContextHolder(); |
| 75 mojo::ScopedHandle* passed_handle = new mojo::ScopedHandle(handle.Pass()); | 75 mojo::ScopedMessagePipeHandle* passed_handle = |
| 76 new mojo::ScopedMessagePipeHandle(handle.Pass()); |
| 76 gin::ModuleRegistry::From(context_holder->context())->LoadModule( | 77 gin::ModuleRegistry::From(context_holder->context())->LoadModule( |
| 77 context_holder->isolate(), | 78 context_holder->isolate(), |
| 78 "main", | 79 "main", |
| 79 base::Bind(RunMain, runner_->GetWeakPtr(), base::Owned(passed_handle))); | 80 base::Bind(RunMain, runner_->GetWeakPtr(), base::Owned(passed_handle))); |
| 80 } | 81 } |
| 81 | 82 |
| 82 void WebUIMojoContextState::FetchModules(const std::vector<std::string>& ids) { | 83 void WebUIMojoContextState::FetchModules(const std::vector<std::string>& ids) { |
| 83 gin::Runner::Scope scoper(runner_.get()); | 84 gin::Runner::Scope scoper(runner_.get()); |
| 84 gin::ContextHolder* context_holder = runner_->GetContextHolder(); | 85 gin::ContextHolder* context_holder = runner_->GetContextHolder(); |
| 85 gin::ModuleRegistry* registry = gin::ModuleRegistry::From( | 86 gin::ModuleRegistry* registry = gin::ModuleRegistry::From( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 const std::vector<std::string>& dependencies) { | 132 const std::vector<std::string>& dependencies) { |
| 132 FetchModules(dependencies); | 133 FetchModules(dependencies); |
| 133 | 134 |
| 134 gin::ContextHolder* context_holder = runner_->GetContextHolder(); | 135 gin::ContextHolder* context_holder = runner_->GetContextHolder(); |
| 135 gin::ModuleRegistry* registry = gin::ModuleRegistry::From( | 136 gin::ModuleRegistry* registry = gin::ModuleRegistry::From( |
| 136 context_holder->context()); | 137 context_holder->context()); |
| 137 registry->AttemptToLoadMoreModules(context_holder->isolate()); | 138 registry->AttemptToLoadMoreModules(context_holder->isolate()); |
| 138 } | 139 } |
| 139 | 140 |
| 140 } // namespace content | 141 } // namespace content |
| OLD | NEW |