| OLD | NEW |
| 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 | 4 |
| 5 #include "chrome/utility/chrome_content_utility_client.h" | 5 #include "chrome/utility/chrome_content_utility_client.h" |
| 6 | 6 |
| 7 #include "base/base64.h" |
| 7 #include "base/bind.h" | 8 #include "base/bind.h" |
| 8 #include "base/base64.h" | |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 13 #include "chrome/browser/importer/external_process_importer_bridge.h" | 14 #include "chrome/browser/importer/external_process_importer_bridge.h" |
| 14 #include "chrome/browser/importer/importer.h" | 15 #include "chrome/browser/importer/importer.h" |
| 15 #include "chrome/browser/importer/profile_import_process_messages.h" | 16 #include "chrome/browser/importer/profile_import_process_messages.h" |
| 16 #include "chrome/common/child_process_logging.h" | 17 #include "chrome/common/child_process_logging.h" |
| 17 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 18 #include "chrome/common/chrome_utility_messages.h" | 19 #include "chrome/common/chrome_utility_messages.h" |
| 19 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_l10n_util.h" | 21 #include "chrome/common/extensions/extension_l10n_util.h" |
| 21 #include "chrome/common/extensions/unpacker.h" | 22 #include "chrome/common/extensions/unpacker.h" |
| 22 #include "chrome/common/extensions/update_manifest.h" | 23 #include "chrome/common/extensions/update_manifest.h" |
| 23 #include "chrome/common/web_resource/web_resource_unpacker.h" | 24 #include "chrome/common/web_resource/web_resource_unpacker.h" |
| 25 #include "chrome/utility/profile_import_handler.h" |
| 24 #include "content/public/utility/utility_thread.h" | 26 #include "content/public/utility/utility_thread.h" |
| 25 #include "printing/backend/print_backend.h" | 27 #include "printing/backend/print_backend.h" |
| 26 #include "printing/page_range.h" | 28 #include "printing/page_range.h" |
| 27 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
| 28 #include "ui/base/ui_base_switches.h" | 30 #include "ui/base/ui_base_switches.h" |
| 29 #include "ui/gfx/rect.h" | 31 #include "ui/gfx/rect.h" |
| 30 #include "webkit/glue/image_decoder.h" | 32 #include "webkit/glue/image_decoder.h" |
| 31 | 33 |
| 32 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
| 33 #include "base/file_util.h" | 35 #include "base/file_util.h" |
| 34 #include "base/memory/scoped_ptr.h" | |
| 35 #include "base/path_service.h" | 36 #include "base/path_service.h" |
| 36 #include "base/win/iat_patch_function.h" | 37 #include "base/win/iat_patch_function.h" |
| 37 #include "base/win/scoped_handle.h" | 38 #include "base/win/scoped_handle.h" |
| 38 #include "content/public/common/content_switches.h" | 39 #include "content/public/common/content_switches.h" |
| 39 #include "printing/emf_win.h" | 40 #include "printing/emf_win.h" |
| 40 #include "ui/gfx/gdi_util.h" | 41 #include "ui/gfx/gdi_util.h" |
| 41 #endif // defined(OS_WIN) | 42 #endif // defined(OS_WIN) |
| 42 | 43 |
| 43 namespace chrome { | 44 namespace chrome { |
| 44 | 45 |
| 45 ChromeContentUtilityClient::ChromeContentUtilityClient() : items_to_import_(0) { | 46 ChromeContentUtilityClient::ChromeContentUtilityClient() { |
| 47 #if !defined(OS_ANDROID) |
| 48 import_handler_.reset(new ProfileImportHandler()); |
| 49 #endif |
| 46 } | 50 } |
| 47 | 51 |
| 48 ChromeContentUtilityClient::~ChromeContentUtilityClient() { | 52 ChromeContentUtilityClient::~ChromeContentUtilityClient() { |
| 49 } | 53 } |
| 50 | 54 |
| 51 void ChromeContentUtilityClient::UtilityThreadStarted() { | 55 void ChromeContentUtilityClient::UtilityThreadStarted() { |
| 52 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
| 53 // Load the pdf plugin before the sandbox is turned on. This is for Windows | 57 // Load the pdf plugin before the sandbox is turned on. This is for Windows |
| 54 // only because we need this DLL only on Windows. | 58 // only because we need this DLL only on Windows. |
| 55 FilePath pdf; | 59 FilePath pdf; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 75 OnUnpackWebResource) | 79 OnUnpackWebResource) |
| 76 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, | 80 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, |
| 77 OnParseUpdateManifest) | 81 OnParseUpdateManifest) |
| 78 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) | 82 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) |
| 79 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) | 83 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) |
| 80 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile, | 84 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile, |
| 81 OnRenderPDFPagesToMetafile) | 85 OnRenderPDFPagesToMetafile) |
| 82 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) | 86 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) |
| 83 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, | 87 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, |
| 84 OnGetPrinterCapsAndDefaults) | 88 OnGetPrinterCapsAndDefaults) |
| 85 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_StartImport, | |
| 86 OnImportStart) | |
| 87 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_CancelImport, | |
| 88 OnImportCancel) | |
| 89 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_ReportImportItemFinished, | |
| 90 OnImportItemFinished) | |
| 91 IPC_MESSAGE_UNHANDLED(handled = false) | 89 IPC_MESSAGE_UNHANDLED(handled = false) |
| 92 IPC_END_MESSAGE_MAP() | 90 IPC_END_MESSAGE_MAP() |
| 91 |
| 92 #if !defined(OS_ANDROID) |
| 93 if (!handled) |
| 94 handled = import_handler_->OnMessageReceived(message); |
| 95 #endif |
| 96 |
| 93 return handled; | 97 return handled; |
| 94 } | 98 } |
| 95 | 99 |
| 96 bool ChromeContentUtilityClient::Send(IPC::Message* message) { | 100 bool ChromeContentUtilityClient::Send(IPC::Message* message) { |
| 97 return content::UtilityThread::Get()->Send(message); | 101 return content::UtilityThread::Get()->Send(message); |
| 98 } | 102 } |
| 99 | 103 |
| 100 void ChromeContentUtilityClient::OnUnpackExtension( | 104 void ChromeContentUtilityClient::OnUnpackExtension( |
| 101 const FilePath& extension_path, | 105 const FilePath& extension_path, |
| 102 const std::string& extension_id, | 106 const std::string& extension_id, |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 printer_name, printer_info)); | 388 printer_name, printer_info)); |
| 385 } else | 389 } else |
| 386 #endif | 390 #endif |
| 387 { | 391 { |
| 388 Send(new ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed( | 392 Send(new ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed( |
| 389 printer_name)); | 393 printer_name)); |
| 390 } | 394 } |
| 391 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | 395 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| 392 } | 396 } |
| 393 | 397 |
| 394 void ChromeContentUtilityClient::OnImportStart( | |
| 395 const importer::SourceProfile& source_profile, | |
| 396 uint16 items, | |
| 397 const DictionaryValue& localized_strings) { | |
| 398 bridge_ = new ExternalProcessImporterBridge( | |
| 399 localized_strings, content::UtilityThread::Get(), | |
| 400 base::MessageLoopProxy::current()); | |
| 401 importer_ = importer::CreateImporterByType(source_profile.importer_type); | |
| 402 if (!importer_) { | |
| 403 Send(new ProfileImportProcessHostMsg_Import_Finished(false, | |
| 404 "Importer could not be created.")); | |
| 405 return; | |
| 406 } | |
| 407 | |
| 408 items_to_import_ = items; | |
| 409 | |
| 410 // Create worker thread in which importer runs. | |
| 411 import_thread_.reset(new base::Thread("import_thread")); | |
| 412 base::Thread::Options options; | |
| 413 options.message_loop_type = MessageLoop::TYPE_IO; | |
| 414 if (!import_thread_->StartWithOptions(options)) { | |
| 415 NOTREACHED(); | |
| 416 ImporterCleanup(); | |
| 417 } | |
| 418 import_thread_->message_loop()->PostTask( | |
| 419 FROM_HERE, base::Bind(&Importer::StartImport, importer_.get(), | |
| 420 source_profile, items, bridge_)); | |
| 421 } | |
| 422 | |
| 423 void ChromeContentUtilityClient::OnImportCancel() { | |
| 424 ImporterCleanup(); | |
| 425 } | |
| 426 | |
| 427 void ChromeContentUtilityClient::OnImportItemFinished(uint16 item) { | |
| 428 items_to_import_ ^= item; // Remove finished item from mask. | |
| 429 // If we've finished with all items, notify the browser process. | |
| 430 if (items_to_import_ == 0) { | |
| 431 Send(new ProfileImportProcessHostMsg_Import_Finished(true, "")); | |
| 432 ImporterCleanup(); | |
| 433 } | |
| 434 } | |
| 435 | |
| 436 void ChromeContentUtilityClient::ImporterCleanup() { | |
| 437 importer_->Cancel(); | |
| 438 importer_ = NULL; | |
| 439 bridge_ = NULL; | |
| 440 import_thread_.reset(); | |
| 441 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | |
| 442 } | |
| 443 | |
| 444 } // namespace chrome | 398 } // namespace chrome |
| OLD | NEW |