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

Side by Side Diff: chrome/common/chrome_plugin_util.cc

Issue 6576020: Remove Gears from Chrome (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: windows fixes Created 9 years, 9 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
« no previous file with comments | « chrome/common/chrome_plugin_util.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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/common/chrome_plugin_util.h"
6
7 #include <algorithm>
8
9 #include "base/command_line.h"
10 #include "base/file_util.h"
11 #include "base/message_loop.h"
12 #include "base/string_util.h"
13 #include "base/utf_string_conversions.h"
14 #include "chrome/common/chrome_plugin_lib.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "content/common/notification_service.h"
17 #include "net/base/load_flags.h"
18 #include "net/http/http_response_headers.h"
19
20 //
21 // ScopableCPRequest
22 //
23
24 ScopableCPRequest::ScopableCPRequest(const char* u, const char* m,
25 CPBrowsingContext c) {
26 pdata = NULL;
27 data = NULL;
28 #if defined(OS_WIN)
29 url = _strdup(u);
30 method = _strdup(m);
31 #else
32 url = strdup(u);
33 method = strdup(m);
34 #endif
35 context = c;
36 }
37
38 ScopableCPRequest::~ScopableCPRequest() {
39 pdata = NULL;
40 data = NULL;
41 free(const_cast<char*>(url));
42 free(const_cast<char*>(method));
43 }
44
45 //
46 // PluginHelper
47 //
48
49 // static
50 void PluginHelper::DestroyAllHelpersForPlugin(ChromePluginLib* plugin) {
51 NotificationService::current()->Notify(
52 NotificationType::CHROME_PLUGIN_UNLOADED,
53 Source<ChromePluginLib>(plugin),
54 NotificationService::NoDetails());
55 }
56
57 PluginHelper::PluginHelper(ChromePluginLib* plugin) : plugin_(plugin) {
58 DCHECK(CalledOnValidThread());
59 registrar_.Add(this, NotificationType::CHROME_PLUGIN_UNLOADED,
60 Source<ChromePluginLib>(plugin_));
61 }
62
63 PluginHelper::~PluginHelper() {
64 DCHECK(CalledOnValidThread());
65 }
66
67 void PluginHelper::Observe(NotificationType type,
68 const NotificationSource& source,
69 const NotificationDetails& details) {
70 DCHECK(CalledOnValidThread());
71 DCHECK(type == NotificationType::CHROME_PLUGIN_UNLOADED);
72 DCHECK(plugin_ == Source<ChromePluginLib>(source).ptr());
73
74 delete this;
75 }
76
77 //
78 // PluginResponseUtils
79 //
80
81 uint32 PluginResponseUtils::CPLoadFlagsToNetFlags(uint32 flags) {
82 uint32 net_flags = 0;
83 #define HANDLE_FLAG(name) \
84 if (flags & CPREQUEST##name) \
85 net_flags |= net::name
86
87 HANDLE_FLAG(LOAD_VALIDATE_CACHE);
88 HANDLE_FLAG(LOAD_BYPASS_CACHE);
89 HANDLE_FLAG(LOAD_PREFERRING_CACHE);
90 HANDLE_FLAG(LOAD_ONLY_FROM_CACHE);
91 HANDLE_FLAG(LOAD_DISABLE_CACHE);
92 HANDLE_FLAG(LOAD_DISABLE_INTERCEPT);
93
94 net_flags |= net::LOAD_ENABLE_UPLOAD_PROGRESS;
95
96 return net_flags;
97 }
98
99 int PluginResponseUtils::GetResponseInfo(
100 const net::HttpResponseHeaders* response_headers,
101 CPResponseInfoType type, void* buf, size_t buf_size) {
102 if (!response_headers)
103 return CPERR_FAILURE;
104
105 switch (type) {
106 case CPRESPONSEINFO_HTTP_STATUS:
107 if (buf && buf_size) {
108 int status = response_headers->response_code();
109 memcpy(buf, &status, std::min(buf_size, sizeof(status)));
110 }
111 break;
112 case CPRESPONSEINFO_HTTP_RAW_HEADERS: {
113 const std::string& headers = response_headers->raw_headers();
114 if (buf_size < headers.size()+1)
115 return static_cast<int>(headers.size()+1);
116 if (buf)
117 memcpy(buf, headers.c_str(), headers.size()+1);
118 break;
119 }
120 default:
121 return CPERR_INVALID_VERSION;
122 }
123
124 return CPERR_SUCCESS;
125 }
126
127 CPError CPB_GetCommandLineArgumentsCommon(const char* url,
128 std::string* arguments) {
129 // TODO(aa): all of this code is only used by Gears, which we are removing.
130 #if defined(OS_WIN)
131 const CommandLine cmd = *CommandLine::ForCurrentProcess();
132 std::wstring arguments_w;
133
134 // Use the same UserDataDir for new launches that we currently have set.
135 FilePath user_data_dir = cmd.GetSwitchValuePath(switches::kUserDataDir);
136 if (!user_data_dir.empty()) {
137 // Make sure user_data_dir is an absolute path.
138 if (file_util::AbsolutePath(&user_data_dir) &&
139 file_util::PathExists(user_data_dir)) {
140 // TODO(evanm): use CommandLine APIs instead of this.
141 arguments_w += std::wstring(L"--") + ASCIIToWide(switches::kUserDataDir) +
142 L"=\"" + user_data_dir.value() + L"\" ";
143 }
144 }
145
146 // Use '--app=url' instead of just 'url' to launch the browser with minimal
147 // chrome.
148 // Note: Do not change this flag! Old Gears shortcuts will break if you do!
149 std::string url_string(url);
150 ReplaceSubstringsAfterOffset(&url_string, 0, "\\", "%5C");
151 ReplaceSubstringsAfterOffset(&url_string, 0, "\"", "%22");
152 ReplaceSubstringsAfterOffset(&url_string, 0, ";", "%3B");
153 ReplaceSubstringsAfterOffset(&url_string, 0, "$", "%24");
154 // Windows shortcuts can't escape % so we use \x instead.
155 ReplaceSubstringsAfterOffset(&url_string, 0, "%", "\\x");
156 std::wstring url_w = UTF8ToWide(url_string);
157 // TODO(evanm): use CommandLine APIs instead of this.
158 arguments_w += std::wstring(L"--") + ASCIIToWide(switches::kApp) +
159 L"=\"" + url_w + L"\"";
160
161 *arguments = WideToUTF8(arguments_w);
162 #else
163 // None of this code is used on non-Windows platforms.
164 NOTREACHED();
165 #endif
166
167 return CPERR_SUCCESS;
168 }
169
170 //
171 // Host functions shared by browser and plugin processes
172 //
173
174 void* STDCALL CPB_Alloc(uint32 size) {
175 return malloc(size);
176 }
177
178 void STDCALL CPB_Free(void* memory) {
179 free(memory);
180 }
OLDNEW
« no previous file with comments | « chrome/common/chrome_plugin_util.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698