OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/common/chrome_plugin_util.h" | 5 #include "chrome/common/chrome_plugin_util.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "chrome/common/chrome_plugin_lib.h" | 11 #include "chrome/common/chrome_plugin_lib.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
14 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
15 #include "net/http/http_response_headers.h" | 15 #include "net/http/http_response_headers.h" |
16 | 16 |
17 // | 17 // |
18 // ScopableCPRequest | 18 // ScopableCPRequest |
19 // | 19 // |
20 | 20 |
21 ScopableCPRequest::ScopableCPRequest(const char* u, const char* m, | 21 ScopableCPRequest::ScopableCPRequest(const char* u, const char* m, |
22 CPBrowsingContext c) { | 22 CPBrowsingContext c) { |
23 pdata = NULL; | 23 pdata = NULL; |
24 data = NULL; | 24 data = NULL; |
25 #if defined(OS_WIN) | |
25 url = _strdup(u); | 26 url = _strdup(u); |
Matt Perry
2009/02/26 01:30:57
Do we have a cross-platform version of this functi
| |
26 method = _strdup(m); | 27 method = _strdup(m); |
28 #else | |
29 url = strdup(u); | |
30 method = strdup(m); | |
31 #endif | |
27 context = c; | 32 context = c; |
28 } | 33 } |
29 | 34 |
30 ScopableCPRequest::~ScopableCPRequest() { | 35 ScopableCPRequest::~ScopableCPRequest() { |
31 pdata = NULL; | 36 pdata = NULL; |
32 data = NULL; | 37 data = NULL; |
33 free(const_cast<char*>(url)); | 38 free(const_cast<char*>(url)); |
34 free(const_cast<char*>(method)); | 39 free(const_cast<char*>(method)); |
35 } | 40 } |
36 | 41 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 HANDLE_FLAG(LOAD_DISABLE_CACHE); | 92 HANDLE_FLAG(LOAD_DISABLE_CACHE); |
88 HANDLE_FLAG(LOAD_DISABLE_INTERCEPT); | 93 HANDLE_FLAG(LOAD_DISABLE_INTERCEPT); |
89 | 94 |
90 net_flags |= net::LOAD_ENABLE_UPLOAD_PROGRESS; | 95 net_flags |= net::LOAD_ENABLE_UPLOAD_PROGRESS; |
91 | 96 |
92 return net_flags; | 97 return net_flags; |
93 } | 98 } |
94 | 99 |
95 int PluginResponseUtils::GetResponseInfo( | 100 int PluginResponseUtils::GetResponseInfo( |
96 const net::HttpResponseHeaders* response_headers, | 101 const net::HttpResponseHeaders* response_headers, |
97 CPResponseInfoType type, void* buf, uint32 buf_size) { | 102 CPResponseInfoType type, void* buf, size_t buf_size) { |
98 if (!response_headers) | 103 if (!response_headers) |
99 return CPERR_FAILURE; | 104 return CPERR_FAILURE; |
100 | 105 |
101 switch (type) { | 106 switch (type) { |
102 case CPRESPONSEINFO_HTTP_STATUS: | 107 case CPRESPONSEINFO_HTTP_STATUS: |
103 if (buf && buf_size) { | 108 if (buf && buf_size) { |
104 int status = response_headers->response_code(); | 109 int status = response_headers->response_code(); |
105 memcpy(buf, &status, std::min(buf_size, sizeof(int))); | 110 memcpy(buf, &status, std::min(buf_size, sizeof(int))); |
106 } | 111 } |
107 break; | 112 break; |
(...skipping 14 matching lines...) Expand all Loading... | |
122 | 127 |
123 CPError CPB_GetCommandLineArgumentsCommon(const char* url, | 128 CPError CPB_GetCommandLineArgumentsCommon(const char* url, |
124 std::string* arguments) { | 129 std::string* arguments) { |
125 const CommandLine cmd = *CommandLine::ForCurrentProcess(); | 130 const CommandLine cmd = *CommandLine::ForCurrentProcess(); |
126 std::wstring arguments_w; | 131 std::wstring arguments_w; |
127 | 132 |
128 // Use the same UserDataDir for new launches that we currently have set. | 133 // Use the same UserDataDir for new launches that we currently have set. |
129 std::wstring user_data_dir = cmd.GetSwitchValue(switches::kUserDataDir); | 134 std::wstring user_data_dir = cmd.GetSwitchValue(switches::kUserDataDir); |
130 if (!user_data_dir.empty()) { | 135 if (!user_data_dir.empty()) { |
131 // Make sure user_data_dir is an absolute path. | 136 // Make sure user_data_dir is an absolute path. |
132 wchar_t user_data_dir_full[MAX_PATH]; | 137 if (file_util::AbsolutePath(&user_data_dir) && |
133 if (_wfullpath(user_data_dir_full, user_data_dir.c_str(), MAX_PATH) && | 138 file_util::PathExists(user_data_dir)) { |
134 file_util::PathExists(user_data_dir_full)) { | |
135 arguments_w += std::wstring(L"--") + switches::kUserDataDir + | 139 arguments_w += std::wstring(L"--") + switches::kUserDataDir + |
136 L'=' + user_data_dir_full; | 140 L'=' + user_data_dir; |
137 } | 141 } |
138 } | 142 } |
139 | 143 |
140 // Use '--app=url' instead of just 'url' to launch the browser with minimal | 144 // Use '--app=url' instead of just 'url' to launch the browser with minimal |
141 // chrome. | 145 // chrome. |
142 // Note: Do not change this flag! Old Gears shortcuts will break if you do! | 146 // Note: Do not change this flag! Old Gears shortcuts will break if you do! |
143 std::wstring url_w = UTF8ToWide(url); | 147 std::wstring url_w = UTF8ToWide(url); |
144 arguments_w += std::wstring(L"--") + switches::kApp + L'=' + url_w; | 148 arguments_w += std::wstring(L"--") + switches::kApp + L'=' + url_w; |
145 | 149 |
146 *arguments = WideToUTF8(arguments_w); | 150 *arguments = WideToUTF8(arguments_w); |
147 | 151 |
148 return CPERR_SUCCESS; | 152 return CPERR_SUCCESS; |
149 } | 153 } |
150 | 154 |
151 // | 155 // |
152 // Host functions shared by browser and plugin processes | 156 // Host functions shared by browser and plugin processes |
153 // | 157 // |
154 | 158 |
155 void* STDCALL CPB_Alloc(uint32 size) { | 159 void* STDCALL CPB_Alloc(uint32 size) { |
156 return malloc(size); | 160 return malloc(size); |
157 } | 161 } |
158 | 162 |
159 void STDCALL CPB_Free(void* memory) { | 163 void STDCALL CPB_Free(void* memory) { |
160 free(memory); | 164 free(memory); |
161 } | 165 } |
162 | 166 |
OLD | NEW |