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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager_util.cc

Issue 10255024: [File Manager] Make sure the new tab is always visible when opening files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/chromeos/extensions/file_manager_util.h" 4 #include "chrome/browser/chromeos/extensions/file_manager_util.h"
5 5
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 result->SetString("transferState", 208 result->SetString("transferState",
209 GDataOperationRegistry::OperationTransferStateToString( 209 GDataOperationRegistry::OperationTransferStateToString(
210 status.transfer_state)); 210 status.transfer_state));
211 result->SetString("transferType", 211 result->SetString("transferType",
212 GDataOperationRegistry::OperationTypeToString(status.operation_type)); 212 GDataOperationRegistry::OperationTypeToString(status.operation_type));
213 result->SetInteger("processed", static_cast<int>(status.progress_current)); 213 result->SetInteger("processed", static_cast<int>(status.progress_current));
214 result->SetInteger("total", static_cast<int>(status.progress_total)); 214 result->SetInteger("total", static_cast<int>(status.progress_total));
215 return result.release(); 215 return result.release();
216 } 216 }
217 217
218 void OpenNewTab(const GURL& url, Profile* profile) {
219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
220 Browser* browser = Browser::GetOrCreateTabbedBrowser(
221 profile ? profile : ProfileManager::GetDefaultProfileOrOffTheRecord());
222 browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK);
223 // If the current browser is not tabbed then the new tab will be created
224 // in a different browser. Make sure it is visible.
225 browser->window()->Show();
226 }
227
218 // Shows a warning message box saying that the file could not be opened. 228 // Shows a warning message box saying that the file could not be opened.
219 void ShowWarningMessageBox(Profile* profile, const FilePath& path) { 229 void ShowWarningMessageBox(Profile* profile, const FilePath& path) {
220 Browser* browser = Browser::GetOrCreateTabbedBrowser(profile); 230 Browser* browser = Browser::GetOrCreateTabbedBrowser(profile);
221 browser::ShowWarningMessageBox( 231 browser::ShowWarningMessageBox(
222 browser->window()->GetNativeHandle(), 232 browser->window()->GetNativeHandle(),
223 l10n_util::GetStringFUTF16( 233 l10n_util::GetStringFUTF16(
224 IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE, 234 IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE,
225 UTF8ToUTF16(path.BaseName().value())), 235 UTF8ToUTF16(path.BaseName().value())),
226 l10n_util::GetStringUTF16(IDS_FILE_BROWSER_ERROR_VIEWING_FILE)); 236 l10n_util::GetStringUTF16(IDS_FILE_BROWSER_ERROR_VIEWING_FILE));
227 } 237 }
(...skipping 12 matching lines...) Expand all
240 gdata::GDataFile* file = entry->AsGDataFile(); 250 gdata::GDataFile* file = entry->AsGDataFile();
241 GURL page_url; 251 GURL page_url;
242 if (file_type == gdata::REGULAR_FILE) { 252 if (file_type == gdata::REGULAR_FILE) {
243 page_url = gdata::util::GetFileResourceUrl(file->resource_id(), 253 page_url = gdata::util::GetFileResourceUrl(file->resource_id(),
244 file->file_name()); 254 file->file_name());
245 } else if (file_type == gdata::HOSTED_DOCUMENT) { 255 } else if (file_type == gdata::HOSTED_DOCUMENT) {
246 page_url = file->alternate_url(); 256 page_url = file->alternate_url();
247 } else { 257 } else {
248 NOTREACHED(); 258 NOTREACHED();
249 } 259 }
250 Browser* browser = Browser::GetOrCreateTabbedBrowser(profile); 260 OpenNewTab(page_url, profile);
251 browser->AddSelectedTabWithURL(page_url, content::PAGE_TRANSITION_LINK);
252 } else { 261 } else {
253 ShowWarningMessageBox(profile, file_path); 262 ShowWarningMessageBox(profile, file_path);
254 } 263 }
255 } 264 }
256 265
257 } // namespace 266 } // namespace
258 267
259 GURL GetFileBrowserExtensionUrl() { 268 GURL GetFileBrowserExtensionUrl() {
260 return GURL(kFileBrowserExtensionUrl); 269 return GURL(kFileBrowserExtensionUrl);
261 } 270 }
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 char buf[1 << 12]; // 4K 569 char buf[1 << 12]; // 4K
561 size_t len = fread(buf, 1, sizeof(buf), file); 570 size_t len = fread(buf, 1, sizeof(buf), file);
562 if (len > 0) { 571 if (len > 0) {
563 contents->append(buf, len); 572 contents->append(buf, len);
564 } 573 }
565 file_util::CloseFile(file); 574 file_util::CloseFile(file);
566 575
567 return len < sizeof(buf); 576 return len < sizeof(buf);
568 } 577 }
569 578
570 void OpenUrlOnUIThread(const GURL& url) {
571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
572 Browser* browser = Browser::GetOrCreateTabbedBrowser(
573 ProfileManager::GetDefaultProfileOrOffTheRecord());
574 browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK);
575 }
576
577 // Reads JSON from a Google Docs file, extracts a document url and opens it 579 // Reads JSON from a Google Docs file, extracts a document url and opens it
578 // in a tab. 580 // in a tab.
579 void ReadUrlFromGDocOnFileThread(const FilePath& file_path) { 581 void ReadUrlFromGDocOnFileThread(const FilePath& file_path) {
580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
581 std::string contents; 583 std::string contents;
582 if (!ReadSmallFileToString(file_path, &contents)) { 584 if (!ReadSmallFileToString(file_path, &contents)) {
583 LOG(ERROR) << "Error reading " << file_path.value(); 585 LOG(ERROR) << "Error reading " << file_path.value();
584 return; 586 return;
585 } 587 }
586 588
587 scoped_ptr<base::Value> root_value; 589 scoped_ptr<base::Value> root_value;
588 root_value.reset(base::JSONReader::Read(contents)); 590 root_value.reset(base::JSONReader::Read(contents));
589 591
590 DictionaryValue* dictionary_value; 592 DictionaryValue* dictionary_value;
591 std::string edit_url_string; 593 std::string edit_url_string;
592 if (!root_value.get() || 594 if (!root_value.get() ||
593 !root_value->GetAsDictionary(&dictionary_value) || 595 !root_value->GetAsDictionary(&dictionary_value) ||
594 !dictionary_value->GetString("url", &edit_url_string)) { 596 !dictionary_value->GetString("url", &edit_url_string)) {
595 LOG(ERROR) << "Invalid JSON in " << file_path.value(); 597 LOG(ERROR) << "Invalid JSON in " << file_path.value();
596 return; 598 return;
597 } 599 }
598 600
599 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 601 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
600 base::Bind(OpenUrlOnUIThread, GURL(edit_url_string))); 602 base::Bind(OpenNewTab, GURL(edit_url_string), (Profile*)NULL));
601 } 603 }
602 604
603 bool TryViewingFile(Profile* profile, const FilePath& path) { 605 bool TryViewingFile(Profile* profile, const FilePath& path) {
604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 606 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
605 607
606 Browser* browser = Browser::GetOrCreateTabbedBrowser(profile);
607
608 std::string file_extension = path.Extension(); 608 std::string file_extension = path.Extension();
609 // For things supported natively by the browser, we should open it 609 // For things supported natively by the browser, we should open it
610 // in a tab. 610 // in a tab.
611 if (IsSupportedBrowserExtension(file_extension.data()) || 611 if (IsSupportedBrowserExtension(file_extension.data()) ||
612 ShouldBeOpenedWithPdfPlugin(profile, file_extension.data())) { 612 ShouldBeOpenedWithPdfPlugin(profile, file_extension.data())) {
613 GURL page_url = net::FilePathToFileURL(path); 613 GURL page_url = net::FilePathToFileURL(path);
614 #if defined(OS_CHROMEOS) 614 #if defined(OS_CHROMEOS)
615 // Override gdata resource to point to internal handler instead of file: 615 // Override gdata resource to point to internal handler instead of file:
616 // URL. 616 // URL.
617 if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) { 617 if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) {
618 gdata::GDataSystemService* system_service = 618 gdata::GDataSystemService* system_service =
619 gdata::GDataSystemServiceFactory::GetForProfile(profile); 619 gdata::GDataSystemServiceFactory::GetForProfile(profile);
620 if (!system_service) 620 if (!system_service)
621 return false; 621 return false;
622 622
623 // Open the file once the file is found. 623 // Open the file once the file is found.
624 system_service->file_system()->FindEntryByPathAsync( 624 system_service->file_system()->FindEntryByPathAsync(
625 gdata::util::ExtractGDataPath(path), 625 gdata::util::ExtractGDataPath(path),
626 base::Bind(&OnGDataFileFound, profile, path, gdata::REGULAR_FILE)); 626 base::Bind(&OnGDataFileFound, profile, path, gdata::REGULAR_FILE));
627 return true; 627 return true;
628 } 628 }
629 #endif 629 #endif
630 browser->AddSelectedTabWithURL(page_url, 630 OpenNewTab(page_url, (Profile*)NULL);
631 content::PAGE_TRANSITION_LINK);
632 return true; 631 return true;
633 } 632 }
634 633
635 if (IsSupportedGDocsExtension(file_extension.data())) { 634 if (IsSupportedGDocsExtension(file_extension.data())) {
636 if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) { 635 if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) {
637 // The file is on Google Docs. Get the Docs from the GData service. 636 // The file is on Google Docs. Get the Docs from the GData service.
638 gdata::GDataSystemService* system_service = 637 gdata::GDataSystemService* system_service =
639 gdata::GDataSystemServiceFactory::GetForProfile(profile); 638 gdata::GDataSystemServiceFactory::GetForProfile(profile);
640 if (!system_service) 639 if (!system_service)
641 return false; 640 return false;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 GDataOperationRegistry::ProgressStatus>::const_iterator iter = 720 GDataOperationRegistry::ProgressStatus>::const_iterator iter =
722 list.begin(); 721 list.begin();
723 iter != list.end(); ++iter) { 722 iter != list.end(); ++iter) {
724 result_list->Append( 723 result_list->Append(
725 ProgessStatusToDictionaryValue(profile, origin_url, *iter)); 724 ProgessStatusToDictionaryValue(profile, origin_url, *iter));
726 } 725 }
727 return result_list.release(); 726 return result_list.release();
728 } 727 }
729 728
730 } // namespace file_manager_util 729 } // namespace file_manager_util
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698