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

Side by Side Diff: chrome/browser/gears_integration.cc

Issue 4979003: Implement web app definition parsing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nacl64 build Created 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/gears_integration.h" 5 #include "chrome/browser/gears_integration.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/chrome_plugin_host.h" 15 #include "chrome/browser/chrome_plugin_host.h"
16 #include "chrome/common/chrome_plugin_util.h" 16 #include "chrome/common/chrome_plugin_util.h"
17 #include "chrome/common/gears_api.h" 17 #include "chrome/common/gears_api.h"
18 #include "chrome/common/web_apps.h"
18 #include "gfx/codec/png_codec.h" 19 #include "gfx/codec/png_codec.h"
19 #include "googleurl/src/gurl.h" 20 #include "googleurl/src/gurl.h"
20 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
21 #include "webkit/glue/dom_operations.h"
22 22
23 // The following 2 helpers are borrowed from the Gears codebase. 23 // The following 2 helpers are borrowed from the Gears codebase.
24 24
25 const size_t kUserPathComponentMaxChars = 64; 25 const size_t kUserPathComponentMaxChars = 64;
26 26
27 // Returns true if and only if the char meets the following criteria: 27 // Returns true if and only if the char meets the following criteria:
28 // 28 //
29 // - visible ASCII 29 // - visible ASCII
30 // - None of the following characters: / \ : * ? " < > | ; , 30 // - None of the following characters: / \ : * ? " < > | ; ,
31 // 31 //
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 return icon_url; 132 return icon_url;
133 } 133 }
134 134
135 // This class holds and manages the data passed to the 135 // This class holds and manages the data passed to the
136 // GEARSPLUGINCOMMAND_CREATE_SHORTCUT plugin command. 136 // GEARSPLUGINCOMMAND_CREATE_SHORTCUT plugin command.
137 class CreateShortcutCommand : public CPCommandInterface { 137 class CreateShortcutCommand : public CPCommandInterface {
138 public: 138 public:
139 CreateShortcutCommand( 139 CreateShortcutCommand(
140 const std::string& name, const std::string& orig_name, 140 const std::string& name, const std::string& orig_name,
141 const std::string& url, const std::string& description, 141 const std::string& url, const std::string& description,
142 const std::vector<webkit_glue::WebApplicationInfo::IconInfo> &icons, 142 const std::vector<WebApplicationInfo::IconInfo> &icons,
143 const SkBitmap& fallback_icon, 143 const SkBitmap& fallback_icon,
144 GearsCreateShortcutCallback* callback) 144 GearsCreateShortcutCallback* callback)
145 : name_(name), url_(url), description_(description), 145 : name_(name), url_(url), description_(description),
146 orig_name_(orig_name), callback_(callback), 146 orig_name_(orig_name), callback_(callback),
147 calling_loop_(MessageLoop::current()) { 147 calling_loop_(MessageLoop::current()) {
148 // shortcut_data_ has the same lifetime as our strings, so we just 148 // shortcut_data_ has the same lifetime as our strings, so we just
149 // point it at their internal data. 149 // point it at their internal data.
150 memset(&shortcut_data_, 0, sizeof(shortcut_data_)); 150 memset(&shortcut_data_, 0, sizeof(shortcut_data_));
151 shortcut_data_.name = name_.c_str(); 151 shortcut_data_.name = name_.c_str();
152 shortcut_data_.url = url_.c_str(); 152 shortcut_data_.url = url_.c_str();
153 shortcut_data_.description = description_.c_str(); 153 shortcut_data_.description = description_.c_str();
154 shortcut_data_.orig_name = orig_name_.c_str(); 154 shortcut_data_.orig_name = orig_name_.c_str();
155 155
156 // Search the icons array for Gears-supported sizes and copy the strings. 156 // Search the icons array for Gears-supported sizes and copy the strings.
157 bool has_icon = false; 157 bool has_icon = false;
158 158
159 for (size_t i = 0; i < icons.size(); ++i) { 159 for (size_t i = 0; i < icons.size(); ++i) {
160 const webkit_glue::WebApplicationInfo::IconInfo& icon = icons[i]; 160 const WebApplicationInfo::IconInfo& icon = icons[i];
161 if (icon.width == 16 && icon.height == 16) { 161 if (icon.width == 16 && icon.height == 16) {
162 has_icon = true; 162 has_icon = true;
163 InitIcon(SIZE_16x16, icon.url, 16, 16); 163 InitIcon(SIZE_16x16, icon.url, 16, 16);
164 } else if (icon.width == 32 && icon.height == 32) { 164 } else if (icon.width == 32 && icon.height == 32) {
165 has_icon = true; 165 has_icon = true;
166 InitIcon(SIZE_32x32, icon.url, 32, 32); 166 InitIcon(SIZE_32x32, icon.url, 32, 32);
167 } else if (icon.width == 48 && icon.height == 48) { 167 } else if (icon.width == 48 && icon.height == 48) {
168 has_icon = true; 168 has_icon = true;
169 InitIcon(SIZE_48x48, icon.url, 48, 48); 169 InitIcon(SIZE_48x48, icon.url, 48, 48);
170 } else if (icon.width == 128 && icon.height == 128) { 170 } else if (icon.width == 128 && icon.height == 128) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 std::string orig_name_; 225 std::string orig_name_;
226 scoped_ptr<GearsCreateShortcutCallback> callback_; 226 scoped_ptr<GearsCreateShortcutCallback> callback_;
227 MessageLoop* calling_loop_; 227 MessageLoop* calling_loop_;
228 }; 228 };
229 229
230 // Allows InvokeLater without adding refcounting. The object is only deleted 230 // Allows InvokeLater without adding refcounting. The object is only deleted
231 // when its last InvokeLater is run anyway. 231 // when its last InvokeLater is run anyway.
232 DISABLE_RUNNABLE_METHOD_REFCOUNT(CreateShortcutCommand); 232 DISABLE_RUNNABLE_METHOD_REFCOUNT(CreateShortcutCommand);
233 233
234 void GearsCreateShortcut( 234 void GearsCreateShortcut(
235 const webkit_glue::WebApplicationInfo& app_info, 235 const WebApplicationInfo& app_info,
236 const string16& fallback_name, 236 const string16& fallback_name,
237 const GURL& fallback_url, 237 const GURL& fallback_url,
238 const SkBitmap& fallback_icon, 238 const SkBitmap& fallback_icon,
239 GearsCreateShortcutCallback* callback) { 239 GearsCreateShortcutCallback* callback) {
240 string16 name = 240 string16 name =
241 !app_info.title.empty() ? app_info.title : fallback_name; 241 !app_info.title.empty() ? app_info.title : fallback_name;
242 std::string orig_name_utf8 = UTF16ToUTF8(name); 242 std::string orig_name_utf8 = UTF16ToUTF8(name);
243 EnsureStringValidPathComponent(name); 243 EnsureStringValidPathComponent(name);
244 244
245 std::string name_utf8 = UTF16ToUTF8(name); 245 std::string name_utf8 = UTF16ToUTF8(name);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 struct RunnableMethodTraits<QueryShortcutsCommand> { 300 struct RunnableMethodTraits<QueryShortcutsCommand> {
301 void RetainCallee(QueryShortcutsCommand* command) {} 301 void RetainCallee(QueryShortcutsCommand* command) {}
302 void ReleaseCallee(QueryShortcutsCommand* command) {} 302 void ReleaseCallee(QueryShortcutsCommand* command) {}
303 }; 303 };
304 304
305 void GearsQueryShortcuts(GearsQueryShortcutsCallback* callback) { 305 void GearsQueryShortcuts(GearsQueryShortcutsCallback* callback) {
306 CPHandleCommand(GEARSPLUGINCOMMAND_GET_SHORTCUT_LIST, 306 CPHandleCommand(GEARSPLUGINCOMMAND_GET_SHORTCUT_LIST,
307 new QueryShortcutsCommand(callback), 307 new QueryShortcutsCommand(callback),
308 0); 308 0);
309 } 309 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698