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

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

Issue 2867008: Show extension icons next to their top-level context menu items.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/extensions/extension_protocols.h" 5 #include "chrome/browser/extensions/extension_protocols.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // This is because an extension must run in a single process, and an incognito 78 // This is because an extension must run in a single process, and an incognito
79 // tab prevents that. 79 // tab prevents that.
80 // TODO(mpcomplete): better error code. 80 // TODO(mpcomplete): better error code.
81 const ResourceDispatcherHostRequestInfo* info = 81 const ResourceDispatcherHostRequestInfo* info =
82 ResourceDispatcherHost::InfoForRequest(request); 82 ResourceDispatcherHost::InfoForRequest(request);
83 if (context->is_off_the_record() && 83 if (context->is_off_the_record() &&
84 info && info->resource_type() == ResourceType::MAIN_FRAME) 84 info && info->resource_type() == ResourceType::MAIN_FRAME)
85 return new URLRequestErrorJob(request, net::ERR_ADDRESS_UNREACHABLE); 85 return new URLRequestErrorJob(request, net::ERR_ADDRESS_UNREACHABLE);
86 86
87 // chrome-extension://extension-id/resource/path.js 87 // chrome-extension://extension-id/resource/path.js
88 FilePath directory_path = context->GetPathForExtension(request->url().host()); 88 const std::string& extension_id = request->url().host();
89 FilePath directory_path = context->GetPathForExtension(extension_id);
89 if (directory_path.value().empty()) { 90 if (directory_path.value().empty()) {
90 LOG(WARNING) << "Failed to GetPathForExtension: " << request->url().host(); 91 LOG(WARNING) << "Failed to GetPathForExtension: " << extension_id;
91 return NULL; 92 return NULL;
92 } 93 }
93 94
94 FilePath resources_path; 95 FilePath resources_path;
95 if (PathService::Get(chrome::DIR_RESOURCES, &resources_path) && 96 if (PathService::Get(chrome::DIR_RESOURCES, &resources_path) &&
96 directory_path.DirName() == resources_path) { 97 directory_path.DirName() == resources_path) {
97 FilePath relative_path = directory_path.BaseName().Append( 98 FilePath relative_path = directory_path.BaseName().Append(
98 extension_file_util::ExtensionURLToRelativeFilePath(request->url())); 99 extension_file_util::ExtensionURLToRelativeFilePath(request->url()));
99 #if defined(OS_WIN) 100 #if defined(OS_WIN)
100 // TODO(tc): This is a hack, we should normalize paths another way. 101 // TODO(tc): This is a hack, we should normalize paths another way.
101 FilePath::StringType path = relative_path.value(); 102 FilePath::StringType path = relative_path.value();
102 std::replace(path.begin(), path.end(), '\\', '/'); 103 std::replace(path.begin(), path.end(), '\\', '/');
103 relative_path = FilePath(path); 104 relative_path = FilePath(path);
104 #endif 105 #endif
105 106
106 // TODO(tc): Make a map of FilePath -> resource ids so we don't have to 107 // TODO(tc): Make a map of FilePath -> resource ids so we don't have to
107 // covert to FilePaths all the time. This will be more useful as we add 108 // covert to FilePaths all the time. This will be more useful as we add
108 // more resources. 109 // more resources.
109 for (size_t i = 0; i < kBookmarkManagerResourcesSize; ++i) { 110 for (size_t i = 0; i < kBookmarkManagerResourcesSize; ++i) {
110 FilePath bm_resource_path = 111 FilePath bm_resource_path =
111 FilePath().AppendASCII(kBookmarkManagerResources[i].name); 112 FilePath().AppendASCII(kBookmarkManagerResources[i].name);
112 if (relative_path == bm_resource_path) { 113 if (relative_path == bm_resource_path) {
113 return new URLRequestResourceBundleJob(request, relative_path, 114 return new URLRequestResourceBundleJob(request, relative_path,
114 kBookmarkManagerResources[i].value); 115 kBookmarkManagerResources[i].value);
115 } 116 }
116 } 117 }
117 } 118 }
118 // TODO(tc): Move all of these files into resources.pak so we don't break 119 // TODO(tc): Move all of these files into resources.pak so we don't break
119 // when updating on Linux. 120 // when updating on Linux.
120 ExtensionResource resource(directory_path, 121 ExtensionResource resource(extension_id, directory_path,
121 extension_file_util::ExtensionURLToRelativeFilePath(request->url())); 122 extension_file_util::ExtensionURLToRelativeFilePath(request->url()));
122 123
123 return new URLRequestFileJob(request, 124 return new URLRequestFileJob(request,
124 resource.GetFilePathOnAnyThreadHack()); 125 resource.GetFilePathOnAnyThreadHack());
125 } 126 }
126 127
127 // Factory registered with URLRequest to create URLRequestJobs for 128 // Factory registered with URLRequest to create URLRequestJobs for
128 // chrome-user-script:/ URLs. 129 // chrome-user-script:/ URLs.
129 static URLRequestJob* CreateUserScriptURLRequestJob(URLRequest* request, 130 static URLRequestJob* CreateUserScriptURLRequestJob(URLRequest* request,
130 const std::string& scheme) { 131 const std::string& scheme) {
131 ChromeURLRequestContext* context = 132 ChromeURLRequestContext* context =
132 static_cast<ChromeURLRequestContext*>(request->context()); 133 static_cast<ChromeURLRequestContext*>(request->context());
133 134
134 // chrome-user-script:/user-script-name.user.js 135 // chrome-user-script:/user-script-name.user.js
135 FilePath directory_path = context->user_script_dir_path(); 136 FilePath directory_path = context->user_script_dir_path();
136 137
137 ExtensionResource resource(directory_path, 138 ExtensionResource resource(request->url().host(), directory_path,
138 extension_file_util::ExtensionURLToRelativeFilePath(request->url())); 139 extension_file_util::ExtensionURLToRelativeFilePath(request->url()));
139 140
140 return new URLRequestFileJob(request, resource.GetFilePath()); 141 return new URLRequestFileJob(request, resource.GetFilePath());
141 } 142 }
142 143
143 void RegisterExtensionProtocols() { 144 void RegisterExtensionProtocols() {
144 URLRequest::RegisterProtocolFactory(chrome::kExtensionScheme, 145 URLRequest::RegisterProtocolFactory(chrome::kExtensionScheme,
145 &CreateExtensionURLRequestJob); 146 &CreateExtensionURLRequestJob);
146 URLRequest::RegisterProtocolFactory(chrome::kUserScriptScheme, 147 URLRequest::RegisterProtocolFactory(chrome::kUserScriptScheme,
147 &CreateUserScriptURLRequestJob); 148 &CreateUserScriptURLRequestJob);
148 } 149 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_menu_manager_unittest.cc ('k') | chrome/browser/extensions/extensions_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698