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

Side by Side Diff: chrome/browser/extensions/extension_resource_protocols.cc

Issue 9909019: Add schema chrome-extension-resource:// for extension resources (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Make some test flaky for OSX Created 8 years, 7 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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.
4
5 #include "chrome/browser/extensions/extension_resource_protocols.h"
6
7 #include "base/file_path.h"
8 #include "base/path_service.h"
9 #include "chrome/common/chrome_paths.h"
10 #include "chrome/common/extensions/extension_file_util.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "net/url_request/url_request_file_job.h"
13
14 namespace {
15
16 class ExtensionResourcesJob : public net::URLRequestFileJob {
17 public:
18 explicit ExtensionResourcesJob(net::URLRequest* request)
19 : net::URLRequestFileJob(request, FilePath()) { }
20
21 virtual void Start() OVERRIDE;
22
23 protected:
24 ~ExtensionResourcesJob() { }
25
26 void ResolvePath();
27 void ResolvePathDone();
28
29 private:
30 content::BrowserThread::ID thread_id_;
31 };
32
33 void ExtensionResourcesJob::Start() {
34 bool result =
35 content::BrowserThread::GetCurrentThreadIdentifier(&thread_id_);
36 CHECK(result) << "Can not get thread id.";
37 content::BrowserThread::PostTask(
38 content::BrowserThread::FILE, FROM_HERE,
39 base::Bind(&ExtensionResourcesJob::ResolvePath, this));
40 }
41
42 void ExtensionResourcesJob::ResolvePath() {
43 FilePath root_path;
44 PathService::Get(chrome::DIR_RESOURCES_EXTENSION, &root_path);
45 file_path_ = extension_file_util::ExtensionResourceURLToFilePath(
46 request()->url(), root_path);
47 content::BrowserThread::PostTask(
48 thread_id_, FROM_HERE,
49 base::Bind(&ExtensionResourcesJob::ResolvePathDone, this));
50 }
51
52 void ExtensionResourcesJob::ResolvePathDone() {
53 net::URLRequestFileJob::Start();
54 }
55
56 class ExtensionResourceProtocolHandler
57 : public net::URLRequestJobFactory::ProtocolHandler {
58 public:
59 ExtensionResourceProtocolHandler() {}
60 virtual ~ExtensionResourceProtocolHandler() {}
61
62 virtual net::URLRequestJob* MaybeCreateJob(
63 net::URLRequest* request) const OVERRIDE;
64
65 private:
66 DISALLOW_COPY_AND_ASSIGN(ExtensionResourceProtocolHandler);
67 };
68
69 // Creates URLRequestJobs for chrome-extension-resource:// URLs.
70 net::URLRequestJob*
71 ExtensionResourceProtocolHandler::MaybeCreateJob(
72 net::URLRequest* request) const {
73 return new ExtensionResourcesJob(request);
74 }
75
76 } // namespace
77
78 net::URLRequestJobFactory::ProtocolHandler*
79 CreateExtensionResourceProtocolHandler() {
80 return new ExtensionResourceProtocolHandler();
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698