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

Unified Diff: content/renderer/mojo_context_state.cc

Issue 1457623004: Serve mojo WebUI resources from the same origin as the WebUI itself. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/mojo_context_state.h ('k') | content/test/data/web_ui_mojo_shell_test.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/mojo_context_state.cc
diff --git a/content/renderer/mojo_context_state.cc b/content/renderer/mojo_context_state.cc
index 6ba37774b68ced26f820ad848bad14ec3c20049b..27de0721239ac42270eab1090d5103d804c85b1b 100644
--- a/content/renderer/mojo_context_state.cc
+++ b/content/renderer/mojo_context_state.cc
@@ -17,6 +17,7 @@
#include "third_party/WebKit/public/platform/WebURLResponse.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"
+#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
using v8::Context;
using v8::HandleScope;
@@ -29,10 +30,6 @@ namespace content {
namespace {
-// All modules have this prefixed to them when downloading.
-// TODO(sky): move this into some common place.
-const char kModulePrefix[] = "chrome://mojo/";
-
void RunMain(base::WeakPtr<gin::Runner> runner,
v8::Local<v8::Value> module) {
v8::Isolate* isolate = runner->GetContextHolder()->isolate();
@@ -46,7 +43,8 @@ void RunMain(base::WeakPtr<gin::Runner> runner,
MojoContextState::MojoContextState(blink::WebFrame* frame,
v8::Local<v8::Context> context)
: frame_(frame),
- module_added_(false) {
+ module_added_(false),
+ module_prefix_(frame_->securityOrigin().toString().utf8() + "/") {
gin::PerContextData* context_data = gin::PerContextData::From(context);
gin::ContextHolder* context_holder = context_data->context_holder();
runner_.reset(new MojoMainRunner(frame_, context_holder));
@@ -87,7 +85,7 @@ void MojoContextState::FetchModules(const std::vector<std::string>& ids) {
}
void MojoContextState::FetchModule(const std::string& id) {
- const GURL url(kModulePrefix + id);
+ const GURL url(module_prefix_ + id);
// TODO(sky): better error checks here?
DCHECK(url.is_valid() && !url.is_empty());
DCHECK(fetched_modules_.find(id) == fetched_modules_.end());
@@ -106,10 +104,10 @@ void MojoContextState::OnFetchModuleComplete(
ResourceFetcher* fetcher,
const blink::WebURLResponse& response,
const std::string& data) {
- DCHECK_EQ(kModulePrefix,
- response.url().string().utf8().substr(0, arraysize(kModulePrefix) - 1));
+ DCHECK_EQ(module_prefix_,
+ response.url().string().utf8().substr(0, module_prefix_.size()));
const std::string module =
- response.url().string().utf8().substr(arraysize(kModulePrefix) - 1);
+ response.url().string().utf8().substr(module_prefix_.size());
// We can't delete fetch right now as the arguments to this function come from
// it and are used below. Instead use a scope_ptr to cleanup.
scoped_ptr<ResourceFetcher> deleter(fetcher);
« no previous file with comments | « content/renderer/mojo_context_state.h ('k') | content/test/data/web_ui_mojo_shell_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698