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

Side by Side Diff: chrome/browser/web_applications/web_app.cc

Issue 2826019: Add tests for chrome/browser/web_applications and mark some code as Win32 and... (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/web_applications/web_app.h" 5 #include "chrome/browser/web_applications/web_app.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <ShellAPI.h> 8 #include <shellapi.h>
9 #endif // defined(OS_WIN) 9 #endif // defined(OS_WIN)
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/md5.h" 17 #include "base/md5.h"
18 #include "base/message_loop.h" 18 #include "base/message_loop.h"
(...skipping 17 matching lines...) Expand all
36 #include "base/env_var.h" 36 #include "base/env_var.h"
37 #endif // defined(OS_LINUX) 37 #endif // defined(OS_LINUX)
38 38
39 #if defined(OS_WIN) 39 #if defined(OS_WIN)
40 #include "base/win_util.h" 40 #include "base/win_util.h"
41 #include "gfx/icon_util.h" 41 #include "gfx/icon_util.h"
42 #endif // defined(OS_WIN) 42 #endif // defined(OS_WIN)
43 43
44 namespace { 44 namespace {
45 45
46 #if defined(OS_WIN)
46 const FilePath::CharType kIconChecksumFileExt[] = FILE_PATH_LITERAL(".ico.md5"); 47 const FilePath::CharType kIconChecksumFileExt[] = FILE_PATH_LITERAL(".ico.md5");
47 48
48 // Returns true if |ch| is in visible ASCII range and not one of 49 // Returns true if |ch| is in visible ASCII range and not one of
49 // "/ \ : * ? " < > | ; ,". 50 // "/ \ : * ? " < > | ; ,".
50 bool IsValidFilePathChar(char16 c) { 51 bool IsValidFilePathChar(char16 c) {
51 if (c < 32) 52 if (c < 32)
52 return false; 53 return false;
53 54
54 switch (c) { 55 switch (c) {
55 case '/': 56 case '/':
(...skipping 18 matching lines...) Expand all
74 string16 file_name; 75 string16 file_name;
75 76
76 for (size_t i = 0; i < name.length(); ++i) { 77 for (size_t i = 0; i < name.length(); ++i) {
77 char16 c = name[i]; 78 char16 c = name[i];
78 if (!IsValidFilePathChar(c)) 79 if (!IsValidFilePathChar(c))
79 c = '_'; 80 c = '_';
80 81
81 file_name += c; 82 file_name += c;
82 } 83 }
83 84
84 #if defined(OS_WIN)
85 return FilePath(file_name); 85 return FilePath(file_name);
86 #elif defined(OS_POSIX)
87 return FilePath(UTF16ToUTF8(file_name));
88 #endif
89 } 86 }
87 #endif // defined(OS_WIN)
90 88
91 // Returns relative directory of given web app url. 89 // Returns relative directory of given web app url.
92 FilePath GetWebAppDir(const GURL& url) { 90 FilePath GetWebAppDir(const GURL& url) {
93 FilePath::StringType host; 91 FilePath::StringType host;
94 FilePath::StringType scheme_port; 92 FilePath::StringType scheme_port;
95 93
96 #if defined(OS_WIN) 94 #if defined(OS_WIN)
97 host = UTF8ToWide(url.host()); 95 host = UTF8ToWide(url.host());
98 scheme_port = (url.has_scheme() ? UTF8ToWide(url.scheme()) : L"http") + 96 scheme_port = (url.has_scheme() ? UTF8ToWide(url.scheme()) : L"http") +
99 FILE_PATH_LITERAL("_") + 97 FILE_PATH_LITERAL("_") +
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 return true; 711 return true;
714 } 712 }
715 713
716 return false; 714 return false;
717 } 715 }
718 716
719 FilePath GetDataDir(const FilePath& profile_path) { 717 FilePath GetDataDir(const FilePath& profile_path) {
720 return profile_path.Append(chrome::kWebAppDirname); 718 return profile_path.Append(chrome::kWebAppDirname);
721 } 719 }
722 720
721 #if defined(TOOLKIT_VIEWS)
723 void GetIconsInfo(const webkit_glue::WebApplicationInfo& app_info, 722 void GetIconsInfo(const webkit_glue::WebApplicationInfo& app_info,
724 IconInfoList* icons) { 723 IconInfoList* icons) {
725 DCHECK(icons); 724 DCHECK(icons);
726 725
727 icons->clear(); 726 icons->clear();
728 for (size_t i = 0; i < app_info.icons.size(); ++i) { 727 for (size_t i = 0; i < app_info.icons.size(); ++i) {
729 // We only take square shaped icons (i.e. width == height). 728 // We only take square shaped icons (i.e. width == height).
730 if (app_info.icons[i].width == app_info.icons[i].height) { 729 if (app_info.icons[i].width == app_info.icons[i].height) {
731 icons->push_back(app_info.icons[i]); 730 icons->push_back(app_info.icons[i]);
732 } 731 }
733 } 732 }
734 733
735 std::sort(icons->begin(), icons->end(), &IconPrecedes); 734 std::sort(icons->begin(), icons->end(), &IconPrecedes);
736 } 735 }
736 #endif
737 737
738 void GetShortcutInfoForTab(TabContents* tab_contents, 738 void GetShortcutInfoForTab(TabContents* tab_contents,
739 ShellIntegration::ShortcutInfo* info) { 739 ShellIntegration::ShortcutInfo* info) {
740 DCHECK(info); // Must provide a valid info. 740 DCHECK(info); // Must provide a valid info.
741 741
742 const webkit_glue::WebApplicationInfo& app_info = 742 const webkit_glue::WebApplicationInfo& app_info =
743 tab_contents->web_app_info(); 743 tab_contents->web_app_info();
744 744
745 info->url = app_info.app_url.is_empty() ? tab_contents->GetURL() : 745 info->url = app_info.app_url.is_empty() ? tab_contents->GetURL() :
746 app_info.app_url; 746 app_info.app_url;
747 info->title = app_info.title.empty() ? 747 info->title = app_info.title.empty() ?
748 (tab_contents->GetTitle().empty() ? UTF8ToUTF16(info->url.spec()) : 748 (tab_contents->GetTitle().empty() ? UTF8ToUTF16(info->url.spec()) :
749 tab_contents->GetTitle()) : 749 tab_contents->GetTitle()) :
750 app_info.title; 750 app_info.title;
751 info->description = app_info.description; 751 info->description = app_info.description;
752 info->favicon = tab_contents->GetFavIcon(); 752 info->favicon = tab_contents->GetFavIcon();
753 } 753 }
754 754
755 void UpdateShortcutForTabContents(TabContents* tab_contents) { 755 void UpdateShortcutForTabContents(TabContents* tab_contents) {
756 #if defined(OS_WIN) 756 #if defined(OS_WIN)
757 // UpdateShortcutWorker will delete itself when it's done. 757 // UpdateShortcutWorker will delete itself when it's done.
758 UpdateShortcutWorker* worker = new UpdateShortcutWorker(tab_contents); 758 UpdateShortcutWorker* worker = new UpdateShortcutWorker(tab_contents);
759 worker->Run(); 759 worker->Run();
760 #endif // defined(OS_WIN) 760 #endif // defined(OS_WIN)
761 } 761 }
762 762
763 }; // namespace web_app 763 }; // namespace web_app
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/web_app.h ('k') | chrome/browser/web_applications/web_app_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698