├── .gitignore ├── .gitmodules ├── LICENSE ├── LICENSE-BRIGHTRAY ├── LICENSE-CHROMIUM ├── NOTES ├── README.md ├── common.gypi ├── docs ├── README.md └── api │ ├── menu.md │ ├── session.md │ ├── webview.md │ └── window.md ├── filename_rules.gypi ├── scripts ├── bootstrap.py ├── build.py ├── chrome_version.h.in ├── config.py ├── create-dist.py ├── update.py └── util.py ├── src ├── api │ ├── api.cc │ ├── api.h │ ├── api_binding.cc │ ├── api_binding.h │ ├── api_server.cc │ ├── api_server.h │ ├── thrust_menu_binding.cc │ ├── thrust_menu_binding.h │ ├── thrust_session_binding.cc │ ├── thrust_session_binding.h │ ├── thrust_window_binding.cc │ └── thrust_window_binding.h ├── app │ ├── content_client.cc │ ├── content_client.h │ ├── library_main.cc │ ├── library_main.h │ ├── main.cc │ ├── main.h │ ├── main_delegate.cc │ ├── main_delegate.h │ └── main_delegate_mac.mm ├── browser │ ├── browser_client.cc │ ├── browser_client.h │ ├── browser_main_parts.cc │ ├── browser_main_parts.h │ ├── browser_main_parts_mac.mm │ ├── dialog │ │ ├── browser_dialogs.h │ │ ├── color_chooser_aura.cc │ │ ├── color_chooser_aura.h │ │ ├── color_chooser_dialog.cc │ │ ├── color_chooser_dialog.h │ │ ├── color_chooser_mac.mm │ │ ├── color_chooser_win.cc │ │ ├── download_manager_delegate.cc │ │ ├── download_manager_delegate.h │ │ ├── download_manager_delegate_gtk.cc │ │ ├── download_manager_delegate_mac.mm │ │ ├── download_manager_delegate_win.cc │ │ ├── file_dialog.h │ │ ├── file_dialog_gtk.cc │ │ ├── file_dialog_mac.mm │ │ ├── file_dialog_win.cc │ │ ├── javascript_dialog_manager.cc │ │ ├── javascript_dialog_manager.h │ │ ├── web_dialog_helper.cc │ │ └── web_dialog_helper.h │ ├── mac │ │ ├── application_mac.h │ │ └── application_mac.mm │ ├── resource_dispatcher_host_delegate.cc │ ├── resource_dispatcher_host_delegate.h │ ├── resources │ │ ├── linux │ │ │ └── application_info_linux.cc │ │ ├── mac │ │ │ ├── Info.plist │ │ │ └── thrust_shell.icns │ │ └── win │ │ │ ├── resource.h │ │ │ ├── thrust_shell.ico │ │ │ └── thrust_shell.rc │ ├── session │ │ ├── thrust_session.cc │ │ ├── thrust_session.h │ │ ├── thrust_session_cookie_store.cc │ │ ├── thrust_session_cookie_store.h │ │ ├── thrust_session_proxy_config_service.cc │ │ ├── thrust_session_proxy_config_service.h │ │ ├── thrust_session_visitedlink_store.cc │ │ └── thrust_session_visitedlink_store.h │ ├── thrust_menu.cc │ ├── thrust_menu.h │ ├── thrust_menu_mac.mm │ ├── thrust_menu_views.cc │ ├── thrust_window.cc │ ├── thrust_window.h │ ├── thrust_window_mac.mm │ ├── thrust_window_views.cc │ ├── ui │ │ ├── accelerator_util.cc │ │ ├── accelerator_util.h │ │ ├── accelerator_util_mac.mm │ │ ├── accelerator_util_views.cc │ │ ├── cocoa │ │ │ ├── event_processing_window.h │ │ │ ├── event_processing_window.mm │ │ │ ├── menu_controller.h │ │ │ └── menu_controller.mm │ │ └── views │ │ │ ├── frameless_view.cc │ │ │ ├── frameless_view.h │ │ │ ├── global_menu_bar_registrar_x11.cc │ │ │ ├── global_menu_bar_registrar_x11.h │ │ │ ├── global_menu_bar_x11.cc │ │ │ ├── global_menu_bar_x11.h │ │ │ ├── menu_bar.cc │ │ │ ├── menu_bar.h │ │ │ ├── menu_delegate.cc │ │ │ ├── menu_delegate.h │ │ │ ├── menu_layout.cc │ │ │ ├── menu_layout.h │ │ │ ├── submenu_button.cc │ │ │ ├── submenu_button.h │ │ │ ├── win_frame_view.cc │ │ │ └── win_frame_view.h │ ├── util │ │ ├── platform_util.h │ │ ├── platform_util_aura.cc │ │ ├── platform_util_linux.cc │ │ └── platform_util_mac.mm │ ├── visitedlink │ │ ├── visitedlink_delegate.h │ │ ├── visitedlink_event_listener.cc │ │ ├── visitedlink_event_listener.h │ │ ├── visitedlink_master.cc │ │ └── visitedlink_master.h │ └── web_view │ │ ├── web_view_constants.cc │ │ ├── web_view_constants.h │ │ ├── web_view_guest.cc │ │ ├── web_view_guest.h │ │ ├── web_view_javascript_dialog_manager.cc │ │ └── web_view_javascript_dialog_manager.h ├── common │ ├── draggable_region.cc │ ├── draggable_region.h │ ├── messages.cc │ ├── messages.h │ ├── resources │ │ └── mac │ │ │ └── Info.plist │ ├── switches.cc │ ├── switches.h │ └── visitedlink │ │ ├── visitedlink_common.cc │ │ ├── visitedlink_common.h │ │ ├── visitedlink_message_generator.cc │ │ ├── visitedlink_message_generator.h │ │ └── visitedlink_messages.h ├── geolocation │ ├── access_token_store.cc │ └── access_token_store.h ├── net │ ├── net_log.cc │ ├── net_log.h │ ├── network_delegate.cc │ ├── network_delegate.h │ ├── url_request_context_getter.cc │ └── url_request_context_getter.h └── renderer │ ├── extensions │ ├── console.cc │ ├── console.h │ ├── context.cc │ ├── context.h │ ├── document_bindings.cc │ ├── document_bindings.h │ ├── local_source_map.cc │ ├── local_source_map.h │ ├── module_system.cc │ ├── module_system.h │ ├── native_handler.cc │ ├── native_handler.h │ ├── object_backed_native_handler.cc │ ├── object_backed_native_handler.h │ ├── remote_bindings.cc │ ├── remote_bindings.h │ ├── request_sender.cc │ ├── request_sender.h │ ├── resources │ │ ├── .gitignore │ │ ├── remote.js │ │ └── web_view.js │ ├── safe_builtins.cc │ ├── safe_builtins.h │ ├── scoped_persistent.h │ ├── script_context.cc │ ├── script_context.h │ ├── static_v8_external_string_resource.cc │ ├── static_v8_external_string_resource.h │ ├── unsafe_persistent.h │ ├── web_view_bindings.cc │ └── web_view_bindings.h │ ├── render_frame_observer.cc │ ├── render_frame_observer.h │ ├── render_process_observer.cc │ ├── render_process_observer.h │ ├── render_view_observer.cc │ ├── render_view_observer.h │ ├── renderer_client.cc │ ├── renderer_client.h │ ├── resources │ └── mac │ │ └── Info.plist │ └── visitedlink │ ├── visitedlink_slave.cc │ └── visitedlink_slave.h ├── thrust_shell.gyp └── tools ├── copy_binary.py ├── mac ├── apply_locales.py ├── create-framework-subdir-symlinks.sh └── make_locale_dirs.sh ├── posix ├── make_locale_paks.sh └── strip.sh └── source_root.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.dylib 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | 15 | .*.swp 16 | *~ 17 | 18 | *.mk 19 | Makefile 20 | *.Makefile 21 | *.pyc 22 | out 23 | 24 | *.xcodeproj 25 | .DS_Store 26 | npm-debug.log 27 | 28 | src/common/chrome_version.h 29 | dummy_session 30 | 31 | dist 32 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vendor/brightray"] 2 | path = vendor/brightray 3 | url = https://github.com/brightray/brightray.git 4 | [submodule "vendor/depot_tools"] 5 | path = vendor/depot_tools 6 | url = https://chromium.googlesource.com/chromium/tools/depot_tools.git 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | 3 | The MIT License (MIT) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /LICENSE-BRIGHTRAY: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 GitHub Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /LICENSE-CHROMIUM: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | 2 | A typical Thrust app is composed of two main components. The platform code 3 | which is language specific and calls into one of Thrust's language binding, 4 | and the HTML5 client code which is executed by Thrusts windows. 5 | 6 | The platform code is generally in charge of serving the client code locally and 7 | provide an API for it to interact with. As the platform code is language 8 | specific, the API reference only describe objects and available methods, using 9 | a pseudocode format, as exposed by Thrust standard I/O API for language bindings 10 | to interact with. Please refer to your specific language bindings for a more 11 | specific documentation and syntax. 12 | 13 | ### API Reference 14 | 15 | Platform code objects: 16 | 17 | - [window](api/window.md) 18 | - [session](api/session.md) 19 | - [menu](api/menu.md) 20 | 21 | Client code modules: 22 | 23 | - remote (coming soon) 24 | 25 | Client custom DOM elements: 26 | 27 | - [`` tag](api/webview.md) 28 | 29 | ### Language Bindings Documentation and Guides 30 | 31 | - [node-thrust](https://github.com/breach/node-thrust) 32 | - [go-thrust](https://github.com/miketheprogrammer/go-thrust/tree/master/doc) 33 | - [pythrust](https://github.com/breach/pythrust) 34 | -------------------------------------------------------------------------------- /docs/api/menu.md: -------------------------------------------------------------------------------- 1 | menu 2 | ==== 3 | 4 | The `menu` object provides an API to create native global application menu 5 | (MacOSX and X11/Unity only) and native context menus. 6 | 7 | Window specific menus on other platform are meant to be handled using client 8 | side code. 9 | 10 | #### Constructor 11 | 12 | #### Event: `execute` 13 | 14 | - `command_id` the command id of the item that was clicked 15 | - `event_flags` event flag integer 16 | 17 | Emitted when a menu item is clicked 18 | 19 | #### Method: `add_item` 20 | 21 | - `command_id` the label command id (see `execute`) 22 | - `label` the item label 23 | 24 | Adds a standard item to the menu 25 | 26 | #### Method: `add_check_item` 27 | 28 | - `command_id` the label command id (see `execute`) 29 | - `label` the item label 30 | 31 | Adds a check item to the menu 32 | 33 | #### Method: `add_radio_item` 34 | 35 | - `command_id` the label command id (see `execute`) 36 | - `label` the item label 37 | - `group_id` radio group 38 | 39 | Adds a radio item to the menu 40 | 41 | #### Method: `add_separator` 42 | 43 | Adds a separator to the menu 44 | 45 | #### Method: `set_checked` 46 | 47 | - `command_id` the command of the item to alter 48 | - `value` true or false 49 | 50 | Sets an item checked or unchecked 51 | 52 | #### Method: `set_enabled` 53 | 54 | - `command_id` the command of the item to alter 55 | - `value` true or false 56 | 57 | Sets an item enabled or disabled 58 | 59 | #### Method: `set_visible` 60 | 61 | - `command_id` the command of the item to alter 62 | - `value` true or false 63 | 64 | #### Method: `set_accelerator` 65 | 66 | - `command_id` the command id of the item to alter 67 | - `accelerator` accelerator string 68 | 69 | Sets the accelerator string for the menu item 70 | 71 | Sets an item visible or invisible 72 | 73 | #### Method: `add_submenu` 74 | 75 | - `menu_id` the menu id to add as submenu 76 | - `label` label for the submenu 77 | - `command_id` command id for the submenu item 78 | 79 | Adds an other menu as submenu of this menu 80 | 81 | #### Method: `clear` 82 | 83 | Clears the menu of all its items 84 | 85 | #### Method: `popup` 86 | 87 | - `window_id` the window id on which to popup the menu 88 | 89 | Popup the menu as a context menu under the current mouse position for the window 90 | specified by its id. 91 | 92 | #### Method: `set_application_menu` 93 | 94 | Sets this menu as the global application menu on MacOSX and X11/Unity 95 | 96 | -------------------------------------------------------------------------------- /filename_rules.gypi: -------------------------------------------------------------------------------- 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 3 | # found in the LICENSE file. 4 | 5 | # This gypi file defines the patterns used for determining whether a 6 | # file is excluded from the build on a given platform. It is 7 | # included by common.gypi for chromium_code. 8 | 9 | { 10 | 'target_conditions': [ 11 | ['OS!="win"', { 12 | 'sources/': [ ['exclude', '_win(_unittest)?\\.(h|cc)$'], 13 | ['exclude', '(^|/)win/'], 14 | ['exclude', '(^|/)win_[^/]*\\.(h|cc)$'] ], 15 | }], 16 | ['OS!="mac"', { 17 | 'sources/': [ ['exclude', '_(cocoa|mac)(_unittest)?\\.(h|cc|mm?)$'], 18 | ['exclude', '(^|/)(cocoa|mac)/'] ], 19 | }], 20 | ['OS!="ios"', { 21 | 'sources/': [ ['exclude', '_ios(_unittest)?\\.(h|cc|mm?)$'], 22 | ['exclude', '(^|/)ios/'] ], 23 | }], 24 | ['OS!="mac" and OS!="ios"', { 25 | 'sources/': [ ['exclude', '\\.mm?$' ] ], 26 | }], 27 | # Do not exclude the linux files on *BSD since most of them can be 28 | # shared at this point. 29 | # In case a file is not needed, it is going to be excluded later on. 30 | # TODO(evan): the above is not correct; we shouldn't build _linux 31 | # files on non-linux. 32 | ['OS!="linux" and OS!="openbsd" and OS!="freebsd"', { 33 | 'sources/': [ 34 | ['exclude', '_linux(_unittest)?\\.(h|cc)$'], 35 | ['exclude', '(^|/)linux_[^/]*\\.(h|cc)$'], 36 | ['exclude', '(^|/)linux/'], 37 | ['exclude', '_x11(_unittest)?\\.(h|cc)$'], 38 | ['exclude', '(^|/)x11_[^/]*\\.(h|cc)$'], 39 | ['exclude', '(^|/)x11/'], 40 | ], 41 | }], 42 | ['OS!="android"', { 43 | 'sources/': [ 44 | ['exclude', '_android(_unittest)?\\.cc$'], 45 | ['exclude', '(^|/)android/'], 46 | ], 47 | }], 48 | ['OS=="win"', { 49 | 'sources/': [ 50 | ['exclude', '_posix(_unittest)?\\.(h|cc)$'], 51 | ['exclude', '(^|/)posix/'], 52 | ], 53 | }], 54 | ['OS!="linux" and OS!="openbsd" and OS!="freebsd"', { 55 | 'sources/': [ 56 | ['exclude', '_xdg(_unittest)?\\.(h|cc)$'], 57 | ], 58 | }], 59 | ['OS!="linux" and OS!="openbsd" and OS!="freebsd"', { 60 | 'sources/': [ 61 | ['exclude', '_gtk(_browsertest|_unittest)?\\.(h|cc)$'], 62 | ['exclude', '(^|/)gtk/'], 63 | ['exclude', '(^|/)gtk_[^/]*\\.(h|cc)$'], 64 | ['exclude', '(^|/)libgtk2ui/'], 65 | ['exclude', '(^|/)x/'], 66 | ], 67 | }], 68 | ['OS=="mac"', { 69 | 'sources/': [ ['exclude', '_aura(_browsertest|_unittest)?\\.(h|cc)$'], 70 | ['exclude', '(^|/)aura/'], 71 | ['exclude', '_views\\.(h|cc)$'], 72 | ['exclude', '(^|/)views/'], 73 | ], 74 | }], 75 | ] 76 | } 77 | -------------------------------------------------------------------------------- /scripts/bootstrap.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import argparse 4 | import os 5 | import sys 6 | import subprocess 7 | 8 | from config import LIBCHROMIUMCONTENT_COMMIT, BASE_URL 9 | 10 | 11 | SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) 12 | VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor') 13 | 14 | 15 | def execute(argv): 16 | try: 17 | return subprocess.check_output(argv, stderr=subprocess.STDOUT) 18 | except subprocess.CalledProcessError as e: 19 | print e.output 20 | raise e 21 | 22 | 23 | def main(): 24 | os.chdir(SOURCE_ROOT) 25 | 26 | args = parse_args() 27 | update_submodules() 28 | bootstrap_brightray(args.url) 29 | create_chrome_version_h() 30 | update_thrust_shell() 31 | 32 | 33 | def parse_args(): 34 | parser = argparse.ArgumentParser(description='Bootstrap this project') 35 | parser.add_argument('-u', '--url', 36 | help='The base URL from which to download ' 37 | 'libchromiumcontent (i.e., the URL you passed to ' 38 | 'libchromiumcontent\'s script/upload script', 39 | default=BASE_URL, 40 | required=False) 41 | return parser.parse_args() 42 | 43 | 44 | def update_submodules(): 45 | execute(['git', 'submodule', 'sync']) 46 | execute(['git', 'submodule', 'update', '--init', '--recursive']) 47 | 48 | 49 | def bootstrap_brightray(url): 50 | bootstrap = os.path.join(VENDOR_DIR, 'brightray', 'script', 'bootstrap') 51 | execute([sys.executable, bootstrap, '--commit', LIBCHROMIUMCONTENT_COMMIT, 52 | url]) 53 | 54 | def create_chrome_version_h(): 55 | version_file = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', 56 | 'libchromiumcontent', 'VERSION') 57 | target_file = os.path.join(SOURCE_ROOT, 'src', 'common', 'chrome_version.h') 58 | template_file = os.path.join(SOURCE_ROOT, 'scripts', 'chrome_version.h.in') 59 | 60 | with open(version_file, 'r') as f: 61 | version = f.read() 62 | with open(template_file, 'r') as f: 63 | template = f.read() 64 | with open(target_file, 'w+') as f: 65 | content = template.replace('{PLACEHOLDER}', version.strip()) 66 | if f.read() != content: 67 | f.write(content) 68 | 69 | def update_thrust_shell(): 70 | update = os.path.join(SOURCE_ROOT, 'scripts', 'update.py') 71 | execute([sys.executable, update]) 72 | 73 | 74 | if __name__ == '__main__': 75 | sys.exit(main()) 76 | -------------------------------------------------------------------------------- /scripts/build.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import argparse 4 | import os 5 | import subprocess 6 | import sys 7 | 8 | 9 | CONFIGURATIONS = ['Release', 'Debug'] 10 | SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) 11 | 12 | 13 | def main(): 14 | os.chdir(SOURCE_ROOT) 15 | 16 | ninja = os.path.join('vendor', 'depot_tools', 'ninja') 17 | if sys.platform == 'win32': 18 | ninja += '.exe' 19 | 20 | args = parse_args() 21 | for config in args.configuration: 22 | build_path = os.path.join('out', config) 23 | ret = subprocess.call([ninja, '-C', build_path, args.target]) 24 | if ret != 0: 25 | sys.exit(ret) 26 | 27 | 28 | def parse_args(): 29 | parser = argparse.ArgumentParser(description='Build thrust_shell') 30 | parser.add_argument('-c', '--configuration', 31 | help='Build with Release or Debug configuration', 32 | nargs='+', 33 | default=CONFIGURATIONS, 34 | required=False) 35 | parser.add_argument('-t', '--target', 36 | help='Build specified target', 37 | default='thrust_shell', 38 | required=False) 39 | return parser.parse_args() 40 | 41 | 42 | if __name__ == '__main__': 43 | sys.exit(main()) 44 | -------------------------------------------------------------------------------- /scripts/chrome_version.h.in: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // See the LICENSE file. 3 | 4 | // This file is generated by script/bootstrap.py, you should never modify it 5 | // by hand. 6 | 7 | #ifndef EXO_BROWSER_COMMON_CHROME_VERSION_H_ 8 | #define EXO_BROWSER_COMMON_CHROME_VERSION_H_ 9 | 10 | #define CHROME_VERSION_STRING "{PLACEHOLDER}" 11 | #define CHROME_VERSION "v" CHROME_VERSION_STRING 12 | 13 | #endif // EXO_BROWSER_COMMON_CHROME_VERSION_H_ 14 | -------------------------------------------------------------------------------- /scripts/config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import platform 4 | import sys 5 | 6 | BASE_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/libchromiumcontent' 7 | LIBCHROMIUMCONTENT_COMMIT = '2dfdf169b582e3f051e1fec3dd7df2bc179e1aa6' 8 | 9 | ARCH = { 10 | 'cygwin': '32bit', 11 | 'darwin': '64bit', 12 | 'linux2': platform.architecture()[0], 13 | 'win32': '32bit', 14 | }[sys.platform] 15 | DIST_ARCH = { 16 | '32bit': 'ia32', 17 | '64bit': 'x64', 18 | }[ARCH] 19 | 20 | TARGET_PLATFORM = { 21 | 'cygwin': 'win32', 22 | 'darwin': 'darwin', 23 | 'linux2': 'linux', 24 | 'win32': 'win32', 25 | }[sys.platform] 26 | -------------------------------------------------------------------------------- /scripts/update.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import subprocess 5 | import sys 6 | 7 | from config import LIBCHROMIUMCONTENT_COMMIT, BASE_URL, DIST_ARCH 8 | 9 | 10 | SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) 11 | 12 | 13 | def main(): 14 | os.chdir(SOURCE_ROOT) 15 | 16 | update_gyp() 17 | 18 | 19 | def update_gyp(): 20 | gyp = os.path.join('vendor', 'brightray', 'vendor', 'gyp', 'gyp_main.py') 21 | python = sys.executable 22 | arch = DIST_ARCH 23 | if sys.platform == 'darwin': 24 | # Only have 64bit build on OS X. 25 | arch = 'x64' 26 | elif sys.platform in ['cygwin', 'win32']: 27 | # Only have 32bit build on Windows. 28 | arch = 'ia32' 29 | if sys.platform == 'cygwin': 30 | # Force using win32 python on cygwin. 31 | python = os.path.join('vendor', 'python_26', 'python.exe') 32 | 33 | ret = subprocess.call([python, gyp, 34 | '-f', 'ninja', '--depth', '.', 'thrust_shell.gyp', 35 | '-Icommon.gypi', '-Ivendor/brightray/brightray.gypi', 36 | '-Dtarget_arch={0}'.format(arch)]) 37 | if ret != 0: 38 | sys.exit(ret) 39 | 40 | 41 | if __name__ == '__main__': 42 | sys.exit(main()) 43 | -------------------------------------------------------------------------------- /src/api/api_binding.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #include 5 | #include 6 | 7 | #include "base/callback.h" 8 | 9 | #include "src/api/api_binding.h" 10 | 11 | namespace thrust_shell { 12 | 13 | APIBinding::APIBinding( 14 | const std::string& type, 15 | const unsigned int id) 16 | : type_(type), 17 | id_(id) 18 | { 19 | } 20 | 21 | APIBinding::~APIBinding() 22 | { 23 | } 24 | 25 | void 26 | APIBinding::InvokeRemoteMethod( 27 | const std::string& method, 28 | scoped_ptr args, 29 | const API::MethodCallback& callback) 30 | { 31 | APIBindingRemote* remote = API::Get()->GetRemote(id_); 32 | if(remote != NULL) { 33 | remote->InvokeMethod(method, args.Pass(), callback); 34 | } 35 | } 36 | 37 | void 38 | APIBinding::EmitEvent( 39 | const std::string& type, 40 | scoped_ptr event) 41 | { 42 | APIBindingRemote* remote = API::Get()->GetRemote(id_); 43 | if(remote != NULL) { 44 | remote->EmitEvent(type, event.Pass()); 45 | } 46 | } 47 | 48 | } // namespace thrust_shell 49 | -------------------------------------------------------------------------------- /src/api/api_binding.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_API_API_BINDING_H_ 5 | #define THRUST_SHELL_API_API_BINDING_H_ 6 | 7 | #include 8 | 9 | #include "base/memory/scoped_ptr.h" 10 | #include "base/memory/ref_counted.h" 11 | #include "base/values.h" 12 | 13 | #include "src/api/api.h" 14 | 15 | namespace base { 16 | class Value; 17 | class DictionaryValue; 18 | } 19 | 20 | namespace thrust_shell { 21 | 22 | // ## APIBinding 23 | // 24 | // Exposes the interface of an object binded to the API 25 | class APIBinding 26 | : public base::RefCountedThreadSafe { 27 | public: 28 | /****************************************************************************/ 29 | /* VIRTUAL INTERFACE */ 30 | /****************************************************************************/ 31 | virtual void CallLocalMethod(const std::string& method, 32 | scoped_ptr args, 33 | const API::MethodCallback& callback) = 0; 34 | 35 | virtual ~APIBinding(); 36 | 37 | std::string type() { return type_; }; 38 | 39 | protected: 40 | /****************************************************************************/ 41 | /* PROTECTED INTERFACE */ 42 | /****************************************************************************/ 43 | void InvokeRemoteMethod(const std::string& method, 44 | scoped_ptr args, 45 | const API::MethodCallback& callback); 46 | void EmitEvent(const std::string& type, 47 | scoped_ptr event); 48 | 49 | APIBinding(const std::string& type, 50 | const unsigned int id); 51 | 52 | std::string type_; 53 | unsigned int id_; 54 | 55 | DISALLOW_COPY_AND_ASSIGN(APIBinding); 56 | }; 57 | 58 | 59 | // ## APIBindingFactory 60 | // 61 | // Factory object used to generate typed binding objects 62 | class APIBindingFactory { 63 | public: 64 | virtual ~APIBindingFactory() {} 65 | 66 | virtual APIBinding* Create(const unsigned int id, 67 | scoped_ptr args) = 0; 68 | }; 69 | 70 | // ## APIBindingRemote 71 | // 72 | // APIBindingRemote Interface to call remote object methods and emit events. 73 | // Remote implementations can be installed through the API::SetRemote method 74 | // and only one remote is associated with a given binding 75 | class APIBindingRemote { 76 | public: 77 | virtual ~APIBindingRemote() {} 78 | 79 | virtual void InvokeMethod(const std::string method, 80 | scoped_ptr args, 81 | const API::MethodCallback& callback) = 0; 82 | virtual void EmitEvent(const std::string type, 83 | scoped_ptr event) = 0; 84 | }; 85 | 86 | 87 | 88 | } // namespace thrust_shell 89 | 90 | #endif // THRUST_SHELL_API_API_BINDING_H_ 91 | -------------------------------------------------------------------------------- /src/api/thrust_menu_binding.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_API_THRUST_MENU_BINDING_H_ 5 | #define THRUST_SHELL_API_THRUST_MENU_BINDING_H_ 6 | 7 | #include "base/callback.h" 8 | 9 | #include "src/api/api_binding.h" 10 | 11 | namespace thrust_shell { 12 | 13 | class ThrustMenu; 14 | 15 | class ThrustMenuBinding : public APIBinding { 16 | public: 17 | /****************************************************************************/ 18 | /* API BINDING INTERFACE */ 19 | /****************************************************************************/ 20 | ThrustMenuBinding(const unsigned int id, 21 | scoped_ptr args); 22 | ~ThrustMenuBinding(); 23 | 24 | virtual void CallLocalMethod( 25 | const std::string& method, 26 | scoped_ptr args, 27 | const API::MethodCallback& callback) OVERRIDE; 28 | 29 | /****************************************************************************/ 30 | /* PUBLIC INTERFACE */ 31 | /****************************************************************************/ 32 | void ExecuteCommand(int command_id, int event_flags); 33 | 34 | ThrustMenu* GetMenu(); 35 | 36 | private: 37 | scoped_ptr menu_; 38 | }; 39 | 40 | 41 | // ## ThrustMenuBindingFactory 42 | // 43 | // Factory object used to generate ThrustMenu bindings 44 | class ThrustMenuBindingFactory : public APIBindingFactory { 45 | public: 46 | ThrustMenuBindingFactory(); 47 | ~ThrustMenuBindingFactory(); 48 | 49 | APIBinding* Create(const unsigned int id, 50 | scoped_ptr args) OVERRIDE; 51 | }; 52 | 53 | } // namespace thrust_shell 54 | 55 | #endif // THRUST_SHELL_API_THRUST_MENU_BINDING_H_ 56 | -------------------------------------------------------------------------------- /src/api/thrust_session_binding.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_API_THRUST_SESSION_BINDING_H_ 5 | #define THRUST_SHELL_API_THRUST_SESSION_BINDING_H_ 6 | 7 | #include "base/callback.h" 8 | 9 | #include "src/api/api_binding.h" 10 | #include "net/cookies/cookie_monster.h" 11 | 12 | namespace thrust_shell { 13 | 14 | class ThrustSession; 15 | 16 | class ThrustSessionBinding : public APIBinding { 17 | public: 18 | 19 | typedef net::CookieMonster::PersistentCookieStore::LoadedCallback 20 | LoadedCallback; 21 | 22 | /****************************************************************************/ 23 | /* API BINDING INTERFACE */ 24 | /****************************************************************************/ 25 | ThrustSessionBinding(const unsigned int id, 26 | scoped_ptr args); 27 | ~ThrustSessionBinding(); 28 | 29 | virtual void CallLocalMethod( 30 | const std::string& method, 31 | scoped_ptr args, 32 | const API::MethodCallback& callback) OVERRIDE; 33 | 34 | /****************************************************************************/ 35 | /* PUBLIC INTERFACE */ 36 | /****************************************************************************/ 37 | void CookiesLoadCallback(const LoadedCallback& loaded_callback, 38 | const std::string& error, 39 | scoped_ptr result); 40 | void CookiesLoad(const LoadedCallback& loaded_callback); 41 | void CookiesLoadForKey(const std::string& key, 42 | const LoadedCallback& loaded_callback); 43 | 44 | void CookiesFlushCallback(const base::Closure& callback, 45 | const std::string& error, 46 | scoped_ptr result); 47 | void CookiesFlush(const base::Closure& callback); 48 | 49 | void CookiesAdd(const net::CanonicalCookie& cc, 50 | unsigned int op_count); 51 | void CookiesUpdateAccessTime(const net::CanonicalCookie& cc, 52 | unsigned int op_count); 53 | void CookiesDelete(const net::CanonicalCookie& cc, 54 | unsigned int op_count); 55 | void CookiesForceKeepSessionState(); 56 | 57 | ThrustSession* GetSession(); 58 | 59 | private: 60 | scoped_ptr session_; 61 | }; 62 | 63 | 64 | // ## ThrustSessionBindingFactory 65 | // 66 | // Factory object used to generate ThrustSession bindings 67 | class ThrustSessionBindingFactory : public APIBindingFactory { 68 | public: 69 | ThrustSessionBindingFactory(); 70 | ~ThrustSessionBindingFactory(); 71 | 72 | APIBinding* Create(const unsigned int id, 73 | scoped_ptr args) OVERRIDE; 74 | }; 75 | 76 | } // namespace thrust_shell 77 | 78 | #endif // THRUST_SHELL_API_THRUST_SESSION_BINDING_H_ 79 | -------------------------------------------------------------------------------- /src/api/thrust_window_binding.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_API_THRUST_SHELL_BINDING_H_ 5 | #define THRUST_SHELL_API_THRUST_SHELL_BINDING_H_ 6 | 7 | #include "base/callback.h" 8 | 9 | #include "src/api/api_binding.h" 10 | 11 | namespace thrust_shell { 12 | 13 | class ThrustWindow; 14 | 15 | class ThrustWindowBinding : public APIBinding { 16 | public: 17 | /****************************************************************************/ 18 | /* API BINDING INTERFACE */ 19 | /****************************************************************************/ 20 | ThrustWindowBinding(const unsigned int id, 21 | scoped_ptr args); 22 | ~ThrustWindowBinding(); 23 | 24 | virtual void CallLocalMethod( 25 | const std::string& method, 26 | scoped_ptr args, 27 | const API::MethodCallback& callback) OVERRIDE; 28 | 29 | /****************************************************************************/ 30 | /* PUBLIC INTERFACE */ 31 | /****************************************************************************/ 32 | ThrustWindow* GetWindow(); 33 | 34 | // API used by ThrustWindow implementations to emit UI related notifications 35 | // to the API. 36 | void EmitClosed(); 37 | void EmitBlur(); 38 | void EmitFocus(); 39 | 40 | void EmitUnresponsive(); 41 | void EmitResponsive(); 42 | void EmitWorkerCrashed(); 43 | 44 | void RemoteSend(const base::DictionaryValue& message); 45 | 46 | private: 47 | scoped_ptr window_; 48 | }; 49 | 50 | 51 | // ## ThrustWindowBindingFactory 52 | // 53 | // Factory object used to generate ThrustWindow bindings 54 | class ThrustWindowBindingFactory : public APIBindingFactory { 55 | public: 56 | ThrustWindowBindingFactory(); 57 | ~ThrustWindowBindingFactory(); 58 | 59 | APIBinding* Create(const unsigned int id, 60 | scoped_ptr args) OVERRIDE; 61 | }; 62 | 63 | } // namespace thrust_shell 64 | 65 | #endif // THRUST_SHELL_API_API_BINDING_H_ 66 | -------------------------------------------------------------------------------- /src/app/content_client.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #include "src/app/content_client.h" 5 | 6 | #include 7 | #include 8 | 9 | #include "src/common/chrome_version.h" 10 | 11 | namespace thrust_shell { 12 | 13 | ContentClient::ContentClient() 14 | { 15 | } 16 | 17 | ContentClient::~ContentClient() 18 | { 19 | } 20 | 21 | std::string 22 | ContentClient::GetProduct() const 23 | { 24 | return "Chrome/" CHROME_VERSION_STRING; 25 | } 26 | 27 | void 28 | ContentClient::AddAdditionalSchemes( 29 | std::vector* standard_schemes, 30 | std::vector* savable_schemes) 31 | { 32 | standard_schemes->push_back("chrome-extension"); 33 | } 34 | 35 | } // namespace thrust_shell 36 | -------------------------------------------------------------------------------- /src/app/content_client.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_APP_CONTENT_CLIENT_H_ 5 | #define THRUST_SHELL_APP_CONTENT_CLIENT_H_ 6 | 7 | #include 8 | #include 9 | 10 | #include "brightray/common/content_client.h" 11 | 12 | namespace thrust_shell { 13 | 14 | class ContentClient : public brightray::ContentClient { 15 | public: 16 | ContentClient(); 17 | virtual ~ContentClient(); 18 | 19 | protected: 20 | /****************************************************************************/ 21 | /* CONTENT_CLIENT IMPLEMENTATION */ 22 | /****************************************************************************/ 23 | virtual std::string GetProduct() const OVERRIDE; 24 | virtual void AddAdditionalSchemes( 25 | std::vector* standard_schemes, 26 | std::vector* savable_schemes) OVERRIDE; 27 | 28 | private: 29 | DISALLOW_COPY_AND_ASSIGN(ContentClient); 30 | }; 31 | 32 | } // namespace thrust_shell 33 | 34 | #endif // THRUST_SHELL_APP_CONTENT_CLIENT_H_ 35 | -------------------------------------------------------------------------------- /src/app/library_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #include "src/app/library_main.h" 5 | 6 | #include "content/public/app/content_main.h" 7 | #include "src/app/main_delegate.h" 8 | 9 | int ThrustShellMain(int argc, const char* argv[]) { 10 | thrust_shell::MainDelegate delegate; 11 | content::ContentMainParams params(&delegate); 12 | params.argc = argc; 13 | params.argv = argv; 14 | return content::ContentMain(params); 15 | } 16 | -------------------------------------------------------------------------------- /src/app/library_main.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_APP_LIBRARY_MAIN_H_ 5 | #define THRUST_SHELL_APP_LIBRARY_MAIN_H_ 6 | 7 | #include "build/build_config.h" 8 | 9 | extern "C" { 10 | 11 | #if defined(OS_MACOSX) 12 | __attribute__ ((visibility ("default"))) 13 | int ThrustShellMain(int argc, const char* argv[]); 14 | #endif 15 | 16 | } 17 | 18 | #endif // THRUST_SHELL_APP_LIBRARY_MAIN_H_ 19 | -------------------------------------------------------------------------------- /src/app/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #include "src/app/main.h" 5 | 6 | #include "src/app/library_main.h" 7 | #include "src/app/main_delegate.h" 8 | 9 | #include "content/public/app/content_main.h" 10 | #include "sandbox/win/src/sandbox_types.h" 11 | 12 | #if defined(OS_WIN) 13 | 14 | #include "content/public/app/startup_helper_win.h" 15 | #include 16 | 17 | int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { 18 | sandbox::SandboxInterfaceInfo sandbox_info = {0}; 19 | content::InitializeSandboxInfo(&sandbox_info); 20 | thrust_shell::MainDelegate delegate; 21 | 22 | content::ContentMainParams params(&delegate); 23 | params.instance = instance; 24 | params.sandbox_info = &sandbox_info; 25 | return content::ContentMain(params); 26 | } 27 | 28 | // defined(OS_WIN) 29 | #elif defined(OS_LINUX) 30 | 31 | int main(int argc, const char* argv[]) { 32 | thrust_shell::MainDelegate delegate; 33 | content::ContentMainParams params(&delegate); 34 | params.argc = argc; 35 | params.argv = argv; 36 | return content::ContentMain(params); 37 | } 38 | 39 | // defined(OS_LINUX) 40 | #else 41 | 42 | int main(int argc, const char* argv[]) { 43 | return ThrustShellMain(argc, argv); 44 | } 45 | 46 | // defined(OS_MACOSX) 47 | #endif 48 | -------------------------------------------------------------------------------- /src/app/main.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_APP_MAIN_H_ 5 | #define THRUST_SHELL_APP_MAIN_H_ 6 | 7 | #include "content/public/app/content_main.h" 8 | 9 | #endif // THRUST_SHELL_APP_MAIN_H_ 10 | -------------------------------------------------------------------------------- /src/app/main_delegate.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #include "src/app/main_delegate.h" 5 | 6 | #include "base/logging.h" 7 | #include "base/command_line.h" 8 | #include "base/debug/stack_trace.h" 9 | #include "content/public/common/content_switches.h" 10 | #include "ui/base/resource/resource_bundle.h" 11 | 12 | #include "src/browser/browser_client.h" 13 | #include "src/renderer/renderer_client.h" 14 | #include "src/app/content_client.h" 15 | 16 | namespace thrust_shell { 17 | 18 | MainDelegate::MainDelegate() { 19 | } 20 | 21 | MainDelegate::~MainDelegate() { 22 | } 23 | 24 | bool 25 | MainDelegate::BasicStartupComplete( 26 | int* exit_code) 27 | { 28 | // Log everything to stderr 29 | logging::LoggingSettings settings; 30 | settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 31 | logging::InitLogging(settings); 32 | 33 | // Logging with pid and timestamp. 34 | logging::SetLogItems(true, false, true, false); 35 | 36 | // Enable convient stack printing. 37 | #if defined(DEBUG) && defined(OS_LINUX) 38 | base::debug::EnableInProcessStackDumping(); 39 | #endif 40 | 41 | return brightray::MainDelegate::BasicStartupComplete(exit_code); 42 | } 43 | 44 | void 45 | MainDelegate::PreSandboxStartup() 46 | { 47 | brightray::MainDelegate::PreSandboxStartup(); 48 | 49 | CommandLine* command_line = CommandLine::ForCurrentProcess(); 50 | std::string process_type = command_line->GetSwitchValueASCII( 51 | switches::kProcessType); 52 | 53 | // Only append arguments for browser process. 54 | if (!process_type.empty()) 55 | return; 56 | 57 | #if defined(OS_WIN) 58 | // Disable the LegacyRenderWidgetHostHWND, it made frameless windows unable 59 | // to move and resize. We may consider enabling it again after upgraded to 60 | // Chrome 38, which should have fixed the problem. 61 | command_line->AppendSwitch(switches::kDisableLegacyIntermediateWindow); 62 | #endif 63 | 64 | // Disable renderer sandbox for most of node's functions. 65 | /* TODO(spolu): Make that switch optional! */ 66 | command_line->AppendSwitch(switches::kNoSandbox); 67 | } 68 | 69 | content::ContentBrowserClient* 70 | MainDelegate::CreateContentBrowserClient() { 71 | browser_client_.reset(new ThrustShellBrowserClient); 72 | return browser_client_.get(); 73 | } 74 | 75 | content::ContentRendererClient* 76 | MainDelegate::CreateContentRendererClient() { 77 | renderer_client_.reset(new ThrustShellRendererClient); 78 | return renderer_client_.get(); 79 | } 80 | 81 | scoped_ptr 82 | MainDelegate::CreateContentClient() { 83 | return scoped_ptr(new ContentClient).Pass(); 84 | } 85 | 86 | void 87 | MainDelegate::AddDataPackFromPath( 88 | ui::ResourceBundle* bundle, 89 | const base::FilePath& pak_dir) 90 | { 91 | #if defined(OS_WIN) 92 | bundle->AddDataPackFromPath( 93 | pak_dir.Append(FILE_PATH_LITERAL("ui_resources_200_percent.pak")), 94 | ui::SCALE_FACTOR_200P); 95 | bundle->AddDataPackFromPath( 96 | pak_dir.Append(FILE_PATH_LITERAL("webkit_resources_200_percent.pak")), 97 | ui::SCALE_FACTOR_200P); 98 | #endif 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/app/main_delegate.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_APP_MAIN_DELEGATE_H_ 5 | #define THRUST_SHELL_APP_MAIN_DELEGATE_H_ 6 | 7 | #include "brightray/common/main_delegate.h" 8 | #include "brightray/common/content_client.h" 9 | 10 | namespace thrust_shell { 11 | 12 | class MainDelegate : public brightray::MainDelegate { 13 | public: 14 | MainDelegate(); 15 | ~MainDelegate(); 16 | 17 | protected: 18 | /****************************************************************************/ 19 | /* CONTENT_MAIN_DELEGATE IMPLEMENTATION */ 20 | /****************************************************************************/ 21 | virtual bool BasicStartupComplete(int* exit_code) OVERRIDE; 22 | virtual void PreSandboxStartup() OVERRIDE; 23 | virtual content::ContentBrowserClient* CreateContentBrowserClient() OVERRIDE; 24 | virtual content::ContentRendererClient* 25 | CreateContentRendererClient() OVERRIDE; 26 | 27 | /****************************************************************************/ 28 | /* BRIGHTRAY_MAIN_DELEGATE IMPLEMENTATION */ 29 | /****************************************************************************/ 30 | virtual scoped_ptr CreateContentClient() OVERRIDE; 31 | virtual void AddDataPackFromPath( 32 | ui::ResourceBundle* bundle, const base::FilePath& pak_dir) OVERRIDE; 33 | #if defined(OS_MACOSX) 34 | virtual void OverrideChildProcessPath() OVERRIDE; 35 | virtual void OverrideFrameworkBundlePath() OVERRIDE; 36 | #endif 37 | 38 | private: 39 | brightray::ContentClient content_client_; 40 | scoped_ptr browser_client_; 41 | scoped_ptr renderer_client_; 42 | 43 | DISALLOW_COPY_AND_ASSIGN(MainDelegate); 44 | }; 45 | 46 | } 47 | 48 | #endif // THRUST_SHELL_APP_MAIN_DELEGATE_H_ 49 | -------------------------------------------------------------------------------- /src/app/main_delegate_mac.mm: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #include "src/app/main_delegate.h" 5 | 6 | #include "base/mac/bundle_locations.h" 7 | #include "base/files/file_path.h" 8 | #include "base/path_service.h" 9 | #include "content/public/common/content_paths.h" 10 | 11 | #include "brightray/common/mac/main_application_bundle.h" 12 | 13 | namespace thrust_shell { 14 | 15 | namespace { 16 | 17 | base::FilePath GetFrameworksPath() { 18 | return brightray::MainApplicationBundlePath().Append("Contents") 19 | .Append("Frameworks"); 20 | } 21 | 22 | } // namespace 23 | 24 | void MainDelegate::OverrideFrameworkBundlePath() { 25 | base::mac::SetOverrideFrameworkBundlePath( 26 | GetFrameworksPath().Append("ThrustShell Framework.framework")); 27 | } 28 | 29 | void MainDelegate::OverrideChildProcessPath() { 30 | base::FilePath helper_path = GetFrameworksPath().Append("ThrustShell Helper.app") 31 | .Append("Contents") 32 | .Append("MacOS") 33 | .Append("ThrustShell Helper"); 34 | PathService::Override(content::CHILD_PROCESS_EXE, helper_path); 35 | } 36 | 37 | } // namespace thrust_shell 38 | -------------------------------------------------------------------------------- /src/browser/browser_main_parts.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/browser_main_parts.h" 6 | 7 | #include "base/bind.h" 8 | #include "base/files/file_path.h" 9 | #include "base/file_util.h" 10 | #include "base/message_loop/message_loop.h" 11 | #include "base/threading/thread.h" 12 | #include "base/threading/thread_restrictions.h" 13 | #include "cc/base/switches.h" 14 | #include "net/base/net_module.h" 15 | #include "net/base/net_util.h" 16 | #include "url/gurl.h" 17 | #include "content/public/common/content_switches.h" 18 | #include "content/public/common/main_function_params.h" 19 | #include "content/public/common/url_constants.h" 20 | #include "content/public/browser/browser_thread.h" 21 | 22 | #include "src/common/switches.h" 23 | #include "src/browser/thrust_window.h" 24 | #include "src/browser/session/thrust_session.h" 25 | #include "src/net/net_log.h" 26 | #include "src/api/api.h" 27 | #include "src/api/api_server.h" 28 | #include "src/api/thrust_window_binding.h" 29 | #include "src/api/thrust_session_binding.h" 30 | #include "src/api/thrust_menu_binding.h" 31 | 32 | 33 | using namespace content; 34 | 35 | namespace thrust_shell { 36 | 37 | // static 38 | ThrustShellMainParts* ThrustShellMainParts::self_ = NULL; 39 | 40 | 41 | ThrustShellMainParts::ThrustShellMainParts() 42 | : system_session_(NULL) 43 | { 44 | DCHECK(!self_) << "Cannot have two ThrustShellBrowserMainParts"; 45 | self_ = this; 46 | api_ = new API(); 47 | } 48 | 49 | ThrustShellMainParts::~ThrustShellMainParts() { 50 | } 51 | 52 | // static 53 | ThrustShellMainParts* 54 | ThrustShellMainParts::Get() 55 | { 56 | DCHECK(self_); 57 | return self_; 58 | } 59 | 60 | brightray::BrowserContext* 61 | ThrustShellMainParts::CreateBrowserContext() { 62 | if(system_session_ == NULL) { 63 | /* We create an off the record session to be used internally. */ 64 | /* This session has a dummy cookie store. Stores nothing. */ 65 | system_session_ = new ThrustSession(NULL, true, "system_session", true); 66 | } 67 | return system_session_; 68 | } 69 | 70 | void 71 | ThrustShellMainParts::PreMainMessageLoopRun() 72 | { 73 | brightray::BrowserMainParts::PreMainMessageLoopRun(); 74 | net_log_.reset(new ThrustShellNetLog()); 75 | 76 | api_->InstallBinding("window", new ThrustWindowBindingFactory()); 77 | api_->InstallBinding("session", new ThrustSessionBindingFactory()); 78 | api_->InstallBinding("menu", new ThrustMenuBindingFactory()); 79 | 80 | api_server_.reset(new APIServer(api_)); 81 | api_server_->Start(); 82 | } 83 | 84 | void ThrustShellMainParts::PostMainMessageLoopRun() 85 | { 86 | brightray::BrowserMainParts::PostMainMessageLoopRun(); 87 | /* system_session_ is cleaned up in the above call. */ 88 | 89 | /* TODO(spolu): Cleanup Remaining ThrustSessions? */ 90 | } 91 | 92 | } // namespace 93 | -------------------------------------------------------------------------------- /src/browser/browser_main_parts.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_BROWSER_MAIN_PARTS_H_ 6 | #define THRUST_SHELL_BROWSER_BROWSER_MAIN_PARTS_H_ 7 | 8 | #include "brightray/browser/browser_main_parts.h" 9 | 10 | #include "base/basictypes.h" 11 | #include "base/threading/thread.h" 12 | #include "base/memory/scoped_ptr.h" 13 | #include "content/public/browser/browser_main_parts.h" 14 | 15 | namespace net { 16 | class NetLog; 17 | } 18 | 19 | namespace content { 20 | struct MainFunctionParams; 21 | } 22 | 23 | namespace thrust_shell { 24 | 25 | class ThrustSession; 26 | class API; 27 | class APIServer; 28 | 29 | class ThrustShellMainParts : public brightray::BrowserMainParts { 30 | public: 31 | 32 | explicit ThrustShellMainParts(); 33 | virtual ~ThrustShellMainParts(); 34 | 35 | static ThrustShellMainParts* Get(); 36 | 37 | /* TODO(spolu) Add App object similar to atom-shell Browser. */ 38 | 39 | // Implementations of brightray::BrowserMainParts. 40 | virtual brightray::BrowserContext* CreateBrowserContext() OVERRIDE; 41 | 42 | // BrowserMainParts overrides. 43 | virtual void PreMainMessageLoopRun() OVERRIDE; 44 | virtual void PostMainMessageLoopRun() OVERRIDE; 45 | #if defined(OS_MACOSX) 46 | virtual void PreMainMessageLoopStart() OVERRIDE; 47 | virtual void PostDestroyThreads() OVERRIDE; 48 | #endif 49 | 50 | net::NetLog* net_log() { 51 | return net_log_.get(); 52 | } 53 | 54 | private: 55 | scoped_ptr net_log_; 56 | 57 | static ThrustShellMainParts* self_; 58 | ThrustSession* system_session_; 59 | 60 | API* api_; 61 | scoped_ptr api_server_; 62 | 63 | DISALLOW_COPY_AND_ASSIGN(ThrustShellMainParts); 64 | }; 65 | 66 | } // namespace thrust_shell 67 | 68 | #endif // THRUST_SHELL_BROWSER_BROWSER_MAIN_PARTS_H_ 69 | -------------------------------------------------------------------------------- /src/browser/browser_main_parts_mac.mm: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/browser_main_parts.h" 6 | 7 | #import 8 | 9 | #include "base/mac/bundle_locations.h" 10 | #include "base/mac/scoped_nsobject.h" 11 | 12 | #include "src/browser/mac/application_mac.h" 13 | 14 | namespace thrust_shell { 15 | 16 | void 17 | ThrustShellMainParts::PreMainMessageLoopStart() 18 | { 19 | // Force the NSApplication subclass to be used. 20 | [ThrustShellApplication sharedApplication]; 21 | 22 | // Prevent Cocoa from turning command-line arguments into 23 | // |-application:openFiles:|, since we already handle them directly. 24 | [[NSUserDefaults standardUserDefaults] 25 | setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"]; 26 | } 27 | 28 | void 29 | ThrustShellMainParts::PostDestroyThreads() { 30 | [[ThrustShellApplication sharedApplication] setDelegate:nil]; 31 | } 32 | 33 | } // namespace thrust_shell 34 | -------------------------------------------------------------------------------- /src/browser/dialog/browser_dialogs.h: -------------------------------------------------------------------------------- 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 3 | // found in the LICENSE-CHROMIUM file. 4 | 5 | #ifndef CHROME_BROWSER_UI_BROWSER_DIALOGS_H_ 6 | #define CHROME_BROWSER_UI_BROWSER_DIALOGS_H_ 7 | 8 | #include "third_party/skia/include/core/SkColor.h" 9 | #include "ui/gfx/native_widget_types.h" 10 | 11 | class SkBitmap; 12 | 13 | namespace content { 14 | class ColorChooser; 15 | class WebContents; 16 | } 17 | 18 | namespace chrome { 19 | 20 | // Shows a color chooser that reports to the given WebContents. 21 | content::ColorChooser* ShowColorChooser(content::WebContents* web_contents, 22 | SkColor initial_color); 23 | 24 | } // namespace chrome 25 | 26 | #endif // CHROME_BROWSER_UI_BROWSER_DIALOGS_H_ 27 | -------------------------------------------------------------------------------- /src/browser/dialog/color_chooser_aura.cc: -------------------------------------------------------------------------------- 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 3 | // found in the LICENSE-CHROMIUM file. 4 | 5 | #include "src/browser/dialog/color_chooser_aura.h" 6 | 7 | #include "content/public/browser/web_contents.h" 8 | #include "ui/views/color_chooser/color_chooser_view.h" 9 | #include "ui/views/widget/widget.h" 10 | 11 | #include "src/browser/dialog/browser_dialogs.h" 12 | 13 | ColorChooserAura::ColorChooserAura(content::WebContents* web_contents, 14 | SkColor initial_color) 15 | : web_contents_(web_contents) { 16 | view_ = new views::ColorChooserView(this, initial_color); 17 | widget_ = views::Widget::CreateWindowWithParent( 18 | view_, web_contents->GetTopLevelNativeWindow()); 19 | widget_->Show(); 20 | } 21 | 22 | void ColorChooserAura::OnColorChosen(SkColor color) { 23 | if (web_contents_) 24 | web_contents_->DidChooseColorInColorChooser(color); 25 | } 26 | 27 | void ColorChooserAura::OnColorChooserDialogClosed() { 28 | view_ = NULL; 29 | widget_ = NULL; 30 | DidEndColorChooser(); 31 | } 32 | 33 | void ColorChooserAura::End() { 34 | if (widget_) { 35 | view_->set_listener(NULL); 36 | widget_->Close(); 37 | view_ = NULL; 38 | widget_ = NULL; 39 | // DidEndColorChooser will invoke Browser::DidEndColorChooser, which deletes 40 | // this. Take care of the call order. 41 | DidEndColorChooser(); 42 | } 43 | } 44 | 45 | void ColorChooserAura::DidEndColorChooser() { 46 | if (web_contents_) 47 | web_contents_->DidEndColorChooser(); 48 | } 49 | 50 | void ColorChooserAura::SetSelectedColor(SkColor color) { 51 | if (view_) 52 | view_->OnColorChanged(color); 53 | } 54 | 55 | // static 56 | ColorChooserAura* ColorChooserAura::Open( 57 | content::WebContents* web_contents, SkColor initial_color) { 58 | return new ColorChooserAura(web_contents, initial_color); 59 | } 60 | 61 | #if !defined(OS_WIN) 62 | namespace chrome { 63 | 64 | content::ColorChooser* ShowColorChooser(content::WebContents* web_contents, 65 | SkColor initial_color) { 66 | return ColorChooserAura::Open(web_contents, initial_color); 67 | } 68 | 69 | } // namespace chrome 70 | #endif // OS_WIN 71 | -------------------------------------------------------------------------------- /src/browser/dialog/color_chooser_aura.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-CHROMIUM file. 4 | 5 | #ifndef CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_AURA_H_ 6 | #define CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_AURA_H_ 7 | 8 | #include "base/basictypes.h" 9 | #include "base/compiler_specific.h" 10 | #include "content/public/browser/color_chooser.h" 11 | #include "ui/views/color_chooser/color_chooser_listener.h" 12 | 13 | namespace content { 14 | class WebContents; 15 | } 16 | 17 | namespace views { 18 | class ColorChooserView; 19 | class Widget; 20 | } 21 | 22 | // TODO(mukai): rename this as -Ash and move to c/b/ui/ash after Linux-aura 23 | // switches to its native color chooser. 24 | class ColorChooserAura : public content::ColorChooser, 25 | public views::ColorChooserListener { 26 | public: 27 | static ColorChooserAura* Open(content::WebContents* web_contents, 28 | SkColor initial_color); 29 | 30 | private: 31 | ColorChooserAura(content::WebContents* web_contents, SkColor initial_color); 32 | 33 | // content::ColorChooser overrides: 34 | virtual void End() OVERRIDE; 35 | virtual void SetSelectedColor(SkColor color) OVERRIDE; 36 | 37 | // views::ColorChooserListener overrides: 38 | virtual void OnColorChosen(SkColor color) OVERRIDE; 39 | virtual void OnColorChooserDialogClosed() OVERRIDE; 40 | 41 | void DidEndColorChooser(); 42 | 43 | // The actual view of the color chooser. No ownership because its parent 44 | // view will take care of its lifetime. 45 | views::ColorChooserView* view_; 46 | 47 | // The widget for the color chooser. No ownership because it's released 48 | // automatically when closed. 49 | views::Widget* widget_; 50 | 51 | // The web contents invoking the color chooser. No ownership because it will 52 | // outlive this class. 53 | content::WebContents* web_contents_; 54 | 55 | DISALLOW_COPY_AND_ASSIGN(ColorChooserAura); 56 | }; 57 | 58 | #endif // CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_AURA_H_ 59 | -------------------------------------------------------------------------------- /src/browser/dialog/color_chooser_dialog.h: -------------------------------------------------------------------------------- 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 3 | // found in the LICENSE-CHROMIUM file. 4 | 5 | #ifndef CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_DIALOG_H_ 6 | #define CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_DIALOG_H_ 7 | 8 | #include "base/memory/ref_counted.h" 9 | #include "third_party/skia/include/core/SkColor.h" 10 | #include "ui/shell_dialogs/base_shell_dialog.h" 11 | #include "ui/shell_dialogs/base_shell_dialog_win.h" 12 | 13 | namespace views { 14 | class ColorChooserListener; 15 | } 16 | 17 | class ColorChooserDialog 18 | : public base::RefCountedThreadSafe, 19 | public ui::BaseShellDialog, 20 | public ui::BaseShellDialogImpl { 21 | public: 22 | ColorChooserDialog(views::ColorChooserListener* listener, 23 | SkColor initial_color, 24 | gfx::NativeWindow owning_window); 25 | virtual ~ColorChooserDialog(); 26 | 27 | // BaseShellDialog: 28 | virtual bool IsRunning(gfx::NativeWindow owning_window) const OVERRIDE; 29 | virtual void ListenerDestroyed() OVERRIDE; 30 | 31 | private: 32 | struct ExecuteOpenParams { 33 | ExecuteOpenParams(SkColor color, RunState run_state, HWND owner); 34 | SkColor color; 35 | RunState run_state; 36 | HWND owner; 37 | }; 38 | 39 | // Called on the dialog thread to show the actual color chooser. This is 40 | // shown modal to |params.owner|. Once it's closed, calls back to 41 | // DidCloseDialog() on the UI thread. 42 | void ExecuteOpen(const ExecuteOpenParams& params); 43 | 44 | // Called on the UI thread when a color chooser is closed. |chose_color| is 45 | // true if the user actually chose a color, in which case |color| is the 46 | // chosen color. Calls back to the |listener_| (if applicable) to notify it 47 | // of the results, and copies the modified array of |custom_colors_| back to 48 | // |g_custom_colors| so future dialogs will see the changes. 49 | void DidCloseDialog(bool chose_color, SkColor color, RunState run_state); 50 | 51 | // Copies the array of colors in |src| to |dst|. 52 | void CopyCustomColors(COLORREF*, COLORREF*); 53 | 54 | // The user's custom colors. Kept process-wide so that they can be persisted 55 | // from one dialog invocation to the next. 56 | static COLORREF g_custom_colors[16]; 57 | 58 | // A copy of the custom colors for the current dialog to display and modify. 59 | // This allows us to safely access the colors even if multiple windows are 60 | // simultaneously showing color choosers (which would cause thread safety 61 | // problems if we gave them direct handles to |g_custom_colors|). 62 | COLORREF custom_colors_[16]; 63 | 64 | // The listener to notify when the user closes the dialog. This may be set to 65 | // NULL before the color chooser is closed, signalling that the listener no 66 | // longer cares about the outcome. 67 | views::ColorChooserListener* listener_; 68 | 69 | DISALLOW_COPY_AND_ASSIGN(ColorChooserDialog); 70 | }; 71 | 72 | #endif // CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_DIALOG_H_ 73 | -------------------------------------------------------------------------------- /src/browser/dialog/download_manager_delegate.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ 6 | #define THRUST_SHELL_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ 7 | 8 | #include "base/compiler_specific.h" 9 | #include "base/memory/ref_counted.h" 10 | #include "base/memory/weak_ptr.h" 11 | #include "content/public/browser/download_manager_delegate.h" 12 | 13 | namespace content { 14 | class DownloadManager; 15 | } 16 | 17 | namespace thrust_shell { 18 | 19 | class ThrustShellDownloadManagerDelegate 20 | : public content::DownloadManagerDelegate { 21 | public: 22 | ThrustShellDownloadManagerDelegate(); 23 | virtual ~ThrustShellDownloadManagerDelegate(); 24 | 25 | void SetDownloadManager(content::DownloadManager* manager); 26 | 27 | virtual void Shutdown() OVERRIDE; 28 | virtual bool DetermineDownloadTarget( 29 | content::DownloadItem* download, 30 | const content::DownloadTargetCallback& callback) OVERRIDE; 31 | virtual bool ShouldOpenDownload( 32 | content::DownloadItem* item, 33 | const content::DownloadOpenDelayedCallback& callback) OVERRIDE; 34 | virtual void GetNextId(const content::DownloadIdCallback& callback) OVERRIDE; 35 | 36 | private: 37 | typedef base::Callback 38 | FilenameDeterminedCallback; 39 | 40 | static void GenerateFilename(const GURL& url, 41 | const std::string& content_disposition, 42 | const std::string& suggested_filename, 43 | const std::string& mime_type, 44 | const base::FilePath& suggested_directory, 45 | const FilenameDeterminedCallback& callback); 46 | void OnDownloadPathGenerated(uint32 download_id, 47 | const content::DownloadTargetCallback& callback, 48 | const base::FilePath& suggested_path); 49 | void ChooseDownloadPath(uint32 download_id, 50 | const content::DownloadTargetCallback& callback, 51 | const base::FilePath& suggested_path); 52 | 53 | content::DownloadManager* download_manager_; 54 | base::FilePath default_download_path_; 55 | bool suppress_prompting_; 56 | base::WeakPtrFactory weak_ptr_factory_; 57 | 58 | friend class base::RefCountedThreadSafe; 59 | 60 | DISALLOW_COPY_AND_ASSIGN(ThrustShellDownloadManagerDelegate); 61 | }; 62 | 63 | } // namespace thrust_shell 64 | 65 | #endif // THRUST_SHELL_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ 66 | -------------------------------------------------------------------------------- /src/browser/dialog/download_manager_delegate_gtk.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/dialog/download_manager_delegate.h" 6 | 7 | #include 8 | 9 | #include "base/bind.h" 10 | #include "base/file_util.h" 11 | #include "base/logging.h" 12 | #include "base/strings/string_util.h" 13 | #include "base/strings/utf_string_conversions.h" 14 | #include "net/base/net_util.h" 15 | #include "content/public/browser/browser_context.h" 16 | #include "content/public/browser/browser_thread.h" 17 | #include "content/public/browser/download_manager.h" 18 | #include "content/public/browser/web_contents.h" 19 | 20 | using namespace content; 21 | 22 | namespace thrust_shell { 23 | 24 | void 25 | ThrustShellDownloadManagerDelegate::ChooseDownloadPath( 26 | uint32 download_id, 27 | const DownloadTargetCallback& callback, 28 | const base::FilePath& suggested_path) 29 | { 30 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 31 | DownloadItem* item = download_manager_->GetDownload(download_id); 32 | if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) 33 | return; 34 | 35 | base::FilePath result; 36 | GtkWidget *dialog; 37 | gfx::NativeWindow parent_window; 38 | std::string base_name = base::FilePath(suggested_path).BaseName().value(); 39 | 40 | parent_window = item->GetWebContents()->GetTopLevelNativeWindow(); 41 | dialog = gtk_file_chooser_dialog_new("Save File", 42 | NULL, 43 | GTK_FILE_CHOOSER_ACTION_SAVE, 44 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 45 | GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, 46 | NULL); 47 | gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), 48 | TRUE); 49 | gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), 50 | base_name.c_str()); 51 | 52 | if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { 53 | char *filename; 54 | filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); 55 | result = base::FilePath(filename); 56 | g_free(filename); 57 | } 58 | gtk_widget_destroy(dialog); 59 | 60 | callback.Run(result, DownloadItem::TARGET_DISPOSITION_PROMPT, 61 | DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, result); 62 | } 63 | 64 | } // namespace thrust_shell 65 | 66 | -------------------------------------------------------------------------------- /src/browser/dialog/download_manager_delegate_mac.mm: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/dialog/download_manager_delegate.h" 6 | 7 | #include 8 | #include 9 | 10 | #include "base/bind.h" 11 | #include "base/file_util.h" 12 | #include "base/files/file_path.h" 13 | #include "base/logging.h" 14 | #include "base/strings/string_util.h" 15 | #include "base/strings/utf_string_conversions.h" 16 | #include "net/base/net_util.h" 17 | #include "content/public/browser/browser_context.h" 18 | #include "content/public/browser/browser_thread.h" 19 | #include "content/public/browser/download_manager.h" 20 | #include "content/public/browser/web_contents.h" 21 | 22 | using namespace content; 23 | 24 | namespace thrust_shell { 25 | 26 | void ThrustShellDownloadManagerDelegate::ChooseDownloadPath( 27 | uint32 download_id, 28 | const DownloadTargetCallback& callback, 29 | const base::FilePath& suggested_path) { 30 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 31 | DownloadItem* item = download_manager_->GetDownload(download_id); 32 | if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) 33 | return; 34 | 35 | base::FilePath result; 36 | std::string base_name = base::FilePath(suggested_path).BaseName().value(); 37 | 38 | NSSavePanel *savePanel = [NSSavePanel savePanel]; 39 | 40 | [savePanel setNameFieldStringValue:[NSString stringWithUTF8String:base_name.c_str()]]; 41 | 42 | if ([savePanel runModal] == NSFileHandlingPanelOKButton) { 43 | char *filename = (char *)[[[savePanel URL] path] UTF8String]; 44 | result = base::FilePath(filename); 45 | } 46 | 47 | callback.Run(result, DownloadItem::TARGET_DISPOSITION_PROMPT, 48 | DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, result); 49 | } 50 | 51 | } // namespace thrust_shell 52 | -------------------------------------------------------------------------------- /src/browser/dialog/download_manager_delegate_win.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/dialog/download_manager_delegate.h" 6 | 7 | #if defined(OS_WIN) 8 | #include 9 | #include 10 | #endif 11 | 12 | #include "base/bind.h" 13 | #include "base/file_util.h" 14 | #include "base/logging.h" 15 | #include "base/strings/string_util.h" 16 | #include "base/strings/utf_string_conversions.h" 17 | #include "content/public/browser/browser_context.h" 18 | #include "content/public/browser/browser_thread.h" 19 | #include "content/public/browser/download_manager.h" 20 | #include "content/public/browser/web_contents.h" 21 | #include "net/base/net_util.h" 22 | 23 | #include "ui/aura/window.h" 24 | #include "ui/aura/window_tree_host.h" 25 | 26 | using namespace content; 27 | 28 | namespace thrust_shell { 29 | 30 | 31 | void 32 | ThrustShellDownloadManagerDelegate::ChooseDownloadPath( 33 | uint32 download_id, 34 | const content::DownloadTargetCallback& callback, 35 | const base::FilePath& suggested_path) 36 | { 37 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 38 | DownloadItem* item = download_manager_->GetDownload(download_id); 39 | if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) 40 | return; 41 | 42 | base::FilePath result; 43 | 44 | std::wstring file_part = base::FilePath(suggested_path).BaseName().value(); 45 | wchar_t file_name[MAX_PATH]; 46 | base::wcslcpy(file_name, file_part.c_str(), arraysize(file_name)); 47 | OPENFILENAME save_as; 48 | ZeroMemory(&save_as, sizeof(save_as)); 49 | save_as.lStructSize = sizeof(OPENFILENAME); 50 | save_as.hwndOwner = (HWND)item->GetWebContents()->GetNativeView()-> 51 | GetHost()->GetAcceleratedWidget(); 52 | save_as.lpstrFile = file_name; 53 | save_as.nMaxFile = arraysize(file_name); 54 | 55 | std::wstring directory; 56 | if (!suggested_path.empty()) 57 | directory = suggested_path.DirName().value(); 58 | 59 | save_as.lpstrInitialDir = directory.c_str(); 60 | save_as.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ENABLESIZING | 61 | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST; 62 | 63 | if (GetSaveFileName(&save_as)) 64 | result = base::FilePath(std::wstring(save_as.lpstrFile)); 65 | 66 | callback.Run(result, DownloadItem::TARGET_DISPOSITION_PROMPT, 67 | DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, result); 68 | } 69 | 70 | } // namespace thrust_shell 71 | -------------------------------------------------------------------------------- /src/browser/dialog/file_dialog.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2014 GitHub, Inc. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_DIALOG_FILE_DIALOG_H_ 6 | #define THRUST_SHELL_BROWSER_DIALOG_FILE_DIALOG_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "base/callback_forward.h" 13 | #include "base/files/file_path.h" 14 | 15 | namespace thrust_shell { 16 | class ThrustWindow; 17 | } 18 | 19 | namespace file_dialog { 20 | 21 | // 22 | typedef std::pair > Filter; 23 | typedef std::vector Filters; 24 | 25 | enum FileDialogProperty { 26 | FILE_DIALOG_OPEN_FILE = 1 << 0, 27 | FILE_DIALOG_OPEN_DIRECTORY = 1 << 1, 28 | FILE_DIALOG_MULTI_SELECTIONS = 1 << 2, 29 | FILE_DIALOG_CREATE_DIRECTORY = 1 << 3, 30 | }; 31 | 32 | typedef base::Callback& paths)> OpenDialogCallback; 34 | 35 | typedef base::Callback SaveDialogCallback; 37 | 38 | bool ShowOpenDialog(thrust_shell::ThrustWindow* parent_window, 39 | const std::string& title, 40 | const base::FilePath& default_path, 41 | const Filters& filters, 42 | int properties, 43 | std::vector* paths); 44 | 45 | void ShowOpenDialog(thrust_shell::ThrustWindow* parent_window, 46 | const std::string& title, 47 | const base::FilePath& default_path, 48 | const Filters& filters, 49 | int properties, 50 | const OpenDialogCallback& callback); 51 | 52 | bool ShowSaveDialog(thrust_shell::ThrustWindow* parent_window, 53 | const std::string& title, 54 | const base::FilePath& default_path, 55 | const Filters& filters, 56 | base::FilePath* path); 57 | 58 | void ShowSaveDialog(thrust_shell::ThrustWindow* parent_window, 59 | const std::string& title, 60 | const base::FilePath& default_path, 61 | const Filters& filters, 62 | const SaveDialogCallback& callback); 63 | 64 | } // namespace file_dialog 65 | 66 | #endif // THRUST_SHELL_BROWSER_DIALOG_FILE_DIALOG_H_ 67 | -------------------------------------------------------------------------------- /src/browser/dialog/javascript_dialog_manager.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/dialog/javascript_dialog_manager.h" 6 | 7 | #include "base/command_line.h" 8 | #include "base/logging.h" 9 | #include "base/strings/utf_string_conversions.h" 10 | #include "net/base/net_util.h" 11 | #include "content/public/browser/web_contents.h" 12 | 13 | #include "src/common/switches.h" 14 | 15 | using namespace content; 16 | 17 | namespace thrust_shell { 18 | 19 | ThrustShellJavaScriptDialogManager::ThrustShellJavaScriptDialogManager() 20 | { 21 | } 22 | 23 | ThrustShellJavaScriptDialogManager::~ThrustShellJavaScriptDialogManager() 24 | { 25 | } 26 | 27 | void 28 | ThrustShellJavaScriptDialogManager::RunJavaScriptDialog( 29 | WebContents* web_contents, 30 | const GURL& origin_url, 31 | const std::string& accept_lang, 32 | JavaScriptMessageType javascript_message_type, 33 | const base::string16& message_text, 34 | const base::string16& default_prompt_text, 35 | const DialogClosedCallback& callback, 36 | bool* did_suppress_message) 37 | { 38 | *did_suppress_message = true; 39 | } 40 | 41 | void 42 | ThrustShellJavaScriptDialogManager::RunBeforeUnloadDialog( 43 | WebContents* web_contents, 44 | const base::string16& message_text, 45 | bool is_reload, 46 | const DialogClosedCallback& callback) 47 | { 48 | callback.Run(true, base::string16()); 49 | } 50 | 51 | 52 | } // namespace thrust_shell 53 | -------------------------------------------------------------------------------- /src/browser/dialog/javascript_dialog_manager.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_UI_DIALOG_JAVASCRIPT_DIALOG_MANAGER_H_ 6 | #define THRUST_SHELL_BROWSER_UI_DIALOG_JAVASCRIPT_DIALOG_MANAGER_H_ 7 | 8 | #include "base/callback_forward.h" 9 | #include "base/compiler_specific.h" 10 | #include "base/memory/scoped_ptr.h" 11 | #include "content/public/browser/javascript_dialog_manager.h" 12 | 13 | namespace thrust_shell { 14 | 15 | //class JavaScriptDialog; 16 | 17 | class ThrustShellJavaScriptDialogManager : 18 | public content::JavaScriptDialogManager { 19 | public: 20 | ThrustShellJavaScriptDialogManager(); 21 | virtual ~ThrustShellJavaScriptDialogManager(); 22 | 23 | // JavaScriptDialogManager overrides 24 | virtual void RunJavaScriptDialog( 25 | content::WebContents* web_contents, 26 | const GURL& origin_url, 27 | const std::string& accept_lang, 28 | content::JavaScriptMessageType javascript_message_type, 29 | const base::string16& message_text, 30 | const base::string16& default_prompt_text, 31 | const DialogClosedCallback& callback, 32 | bool* did_suppress_message) OVERRIDE; 33 | 34 | virtual void RunBeforeUnloadDialog( 35 | content::WebContents* web_contents, 36 | const base::string16& message_text, 37 | bool is_reload, 38 | const DialogClosedCallback& callback) OVERRIDE; 39 | 40 | virtual void CancelActiveAndPendingDialogs( 41 | content::WebContents* web_contents) OVERRIDE {} 42 | 43 | virtual void WebContentsDestroyed( 44 | content::WebContents* web_contents) OVERRIDE {} 45 | 46 | private: 47 | DISALLOW_COPY_AND_ASSIGN(ThrustShellJavaScriptDialogManager); 48 | }; 49 | 50 | } // namespace thrust_shell 51 | 52 | #endif // THRUST_SHELL_BROWSER_UI_DIALOG_JAVASCRIPT_DIALOG_MANAGER_H_ 53 | -------------------------------------------------------------------------------- /src/browser/dialog/web_dialog_helper.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/dialog/web_dialog_helper.h" 6 | 7 | #include 8 | 9 | #include "base/bind.h" 10 | #include "base/files/file_enumerator.h" 11 | #include "base/strings/utf_string_conversions.h" 12 | #include "content/public/browser/render_view_host.h" 13 | #include "content/public/browser/web_contents.h" 14 | #include "ui/shell_dialogs/selected_file_info.h" 15 | 16 | #include "src/browser/dialog/file_dialog.h" 17 | 18 | namespace thrust_shell { 19 | 20 | ThrustShellWebDialogHelper::ThrustShellWebDialogHelper( 21 | ThrustWindow* window) 22 | : window_(window), 23 | weak_factory_(this) { 24 | } 25 | 26 | ThrustShellWebDialogHelper::~ThrustShellWebDialogHelper() 27 | { 28 | } 29 | 30 | void 31 | ThrustShellWebDialogHelper::RunFileChooser( 32 | content::WebContents* web_contents, 33 | const content::FileChooserParams& params) 34 | { 35 | std::vector result; 36 | if (params.mode == content::FileChooserParams::Save) { 37 | base::FilePath path; 38 | if (file_dialog::ShowSaveDialog(window_, 39 | base::UTF16ToUTF8(params.title), 40 | params.default_file_name, 41 | file_dialog::Filters(), 42 | &path)) 43 | result.push_back(ui::SelectedFileInfo(path, path)); 44 | } else { 45 | int flags = file_dialog::FILE_DIALOG_CREATE_DIRECTORY; 46 | switch (params.mode) { 47 | case content::FileChooserParams::OpenMultiple: 48 | flags |= file_dialog::FILE_DIALOG_MULTI_SELECTIONS; 49 | case content::FileChooserParams::Open: 50 | flags |= file_dialog::FILE_DIALOG_OPEN_FILE; 51 | break; 52 | case content::FileChooserParams::UploadFolder: 53 | flags |= file_dialog::FILE_DIALOG_OPEN_DIRECTORY; 54 | break; 55 | default: 56 | NOTREACHED(); 57 | } 58 | 59 | std::vector paths; 60 | if (file_dialog::ShowOpenDialog(window_, 61 | base::UTF16ToUTF8(params.title), 62 | params.default_file_name, 63 | file_dialog::Filters(), 64 | flags, 65 | &paths)) 66 | for (auto& path : paths) 67 | result.push_back(ui::SelectedFileInfo(path, path)); 68 | } 69 | 70 | web_contents->GetRenderViewHost()->FilesSelectedInChooser( 71 | result, params.mode); 72 | } 73 | 74 | void 75 | ThrustShellWebDialogHelper::EnumerateDirectory( 76 | content::WebContents* web_contents, 77 | int request_id, 78 | const base::FilePath& dir) 79 | { 80 | int types = base::FileEnumerator::FILES | 81 | base::FileEnumerator::DIRECTORIES | 82 | base::FileEnumerator::INCLUDE_DOT_DOT; 83 | base::FileEnumerator file_enum(dir, false, types); 84 | 85 | base::FilePath path; 86 | std::vector paths; 87 | while (!(path = file_enum.Next()).empty()) 88 | paths.push_back(path); 89 | 90 | web_contents->GetRenderViewHost()->DirectoryEnumerationFinished( 91 | request_id, paths); 92 | } 93 | 94 | } // namespace thrust_shell 95 | -------------------------------------------------------------------------------- /src/browser/dialog/web_dialog_helper.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2014 GitHub, Inc. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_DIALOG_WEB_DIALOG_HELPER_H_ 6 | #define THRUST_SHELL_BROWSER_DIALOG_WEB_DIALOG_HELPER_H_ 7 | 8 | #include "base/memory/weak_ptr.h" 9 | 10 | namespace base { 11 | class FilePath; 12 | } 13 | 14 | namespace content { 15 | struct FileChooserParams; 16 | class WebContents; 17 | } 18 | 19 | namespace thrust_shell { 20 | 21 | class ThrustWindow; 22 | 23 | class ThrustShellWebDialogHelper { 24 | public: 25 | explicit ThrustShellWebDialogHelper(ThrustWindow* window); 26 | ~ThrustShellWebDialogHelper(); 27 | 28 | void RunFileChooser(content::WebContents* web_contents, 29 | const content::FileChooserParams& params); 30 | void EnumerateDirectory(content::WebContents* web_contents, 31 | int request_id, 32 | const base::FilePath& path); 33 | 34 | private: 35 | ThrustWindow* window_; 36 | 37 | base::WeakPtrFactory weak_factory_; 38 | 39 | DISALLOW_COPY_AND_ASSIGN(ThrustShellWebDialogHelper); 40 | }; 41 | 42 | } // namespace thrust_shell 43 | 44 | #endif // THRUST_SHELL_BROWSER_DIALOG_WEB_DIALOG_HELPER_H_ 45 | -------------------------------------------------------------------------------- /src/browser/mac/application_mac.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_MAC_THRUST_SHELL_APPLICATION_MAC_H_ 6 | #define THRUST_SHELL_BROWSER_MAC_THRUST_SHELL_APPLICATION_MAC_H_ 7 | 8 | #include "base/mac/scoped_sending_event.h" 9 | #include "base/message_loop/message_pump_mac.h" 10 | 11 | @interface ThrustShellApplication : NSApplication { 13 | @private 14 | BOOL handlingSendEvent_; 15 | } 16 | 17 | + (ThrustShellApplication*)sharedApplication; 18 | 19 | // CrAppProtocol: 20 | - (BOOL)isHandlingSendEvent; 21 | 22 | // CrAppControlProtocol: 23 | - (void)setHandlingSendEvent:(BOOL)handlingSendEvent; 24 | 25 | @end 26 | 27 | #endif // THRUST_SHELL_BROWSER_MAC_THRUST_SHELL_APPLICATION_MAC_H_ 28 | -------------------------------------------------------------------------------- /src/browser/mac/application_mac.mm: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/mac/application_mac.h" 6 | 7 | #include "base/auto_reset.h" 8 | #include "url/gurl.h" 9 | 10 | #include "src/browser/thrust_window.h" 11 | #include "src/browser/browser_client.h" 12 | 13 | #include 14 | #include 15 | 16 | @implementation ThrustShellApplication 17 | 18 | + (ThrustShellApplication*)sharedApplication { 19 | return (ThrustShellApplication*)[super sharedApplication]; 20 | } 21 | 22 | - (BOOL)isHandlingSendEvent { 23 | return handlingSendEvent_; 24 | } 25 | 26 | - (void)sendEvent:(NSEvent*)event { 27 | base::AutoReset scoper(&handlingSendEvent_, YES); 28 | [super sendEvent:event]; 29 | } 30 | 31 | - (void)setHandlingSendEvent:(BOOL)handlingSendEvent { 32 | handlingSendEvent_ = handlingSendEvent; 33 | } 34 | 35 | - (void)terminate:(id)sender { 36 | /* We override the normal termination and simply send a kill signal to the */ 37 | /* process to comply with the linux behaviour. */ 38 | /* TODO(spolu): Send event to API */ 39 | kill(getpid(), SIGINT); 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /src/browser/resource_dispatcher_host_delegate.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/resource_dispatcher_host_delegate.h" 6 | 7 | #include "base/command_line.h" 8 | /* TODO(spolu): introduce ShellLogin Dialog (see content) */ 9 | //#include "content/shell/shell_login_dialog.h" 10 | 11 | #include "src/common/switches.h" 12 | 13 | using namespace content; 14 | 15 | namespace thrust_shell { 16 | 17 | ThrustShellResourceDispatcherHostDelegate:: 18 | ThrustShellResourceDispatcherHostDelegate() 19 | { 20 | } 21 | 22 | ThrustShellResourceDispatcherHostDelegate:: 23 | ~ThrustShellResourceDispatcherHostDelegate() 24 | { 25 | } 26 | 27 | ResourceDispatcherHostLoginDelegate* 28 | ThrustShellResourceDispatcherHostDelegate::CreateLoginDelegate( 29 | net::AuthChallengeInfo* auth_info, 30 | net::URLRequest* request) 31 | { 32 | /* TODO(spolu): introduce ShellLogin Dialog (see content) */ 33 | return NULL; 34 | } 35 | 36 | } // namespace thrust_shell 37 | -------------------------------------------------------------------------------- /src/browser/resource_dispatcher_host_delegate.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ 6 | #define THRUST_SHELL_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ 7 | 8 | #include "base/compiler_specific.h" 9 | #include "content/public/browser/resource_dispatcher_host_delegate.h" 10 | 11 | namespace thrust_shell { 12 | 13 | class ThrustShellResourceDispatcherHostDelegate 14 | : public content::ResourceDispatcherHostDelegate { 15 | public: 16 | ThrustShellResourceDispatcherHostDelegate(); 17 | virtual ~ThrustShellResourceDispatcherHostDelegate(); 18 | 19 | // ResourceDispatcherHostDelegate implementation. 20 | virtual content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( 21 | net::AuthChallengeInfo* auth_info, 22 | net::URLRequest* request) OVERRIDE; 23 | 24 | DISALLOW_COPY_AND_ASSIGN(ThrustShellResourceDispatcherHostDelegate); 25 | }; 26 | 27 | } // namespace thrust_shell 28 | 29 | #endif // THRUST_SHELL_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ 30 | -------------------------------------------------------------------------------- /src/browser/resources/linux/application_info_linux.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "base/logging.h" 3 | 4 | namespace brightray { 5 | 6 | std::string GetApplicationName() { return "ThrustShell"; } 7 | std::string GetApplicationVersion() { return "0.7.0.0"; } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/browser/resources/mac/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${PRODUCT_NAME} 11 | CFBundleIconFile 12 | thrust_shell.icns 13 | CFBundleIdentifier 14 | org.breach.${PRODUCT_NAME} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleVersion 18 | 0.7.0 19 | CFBundlePackageType 20 | APPL 21 | LSMinimumSystemVersion 22 | 10.8.0 23 | CFBundleName 24 | ${PRODUCT_NAME} 25 | 29 | NSPrincipalClass 30 | 31 | 32 | ThrustShellApplication 33 | LSFileQuarantineEnabled 34 | 35 | NSSupportsAutomaticGraphicsSwitching 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/browser/resources/mac/thrust_shell.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/breach/thrust/128210dffe10d6a0f5119c9fdfdded98f604feec/src/browser/resources/mac/thrust_shell.icns -------------------------------------------------------------------------------- /src/browser/resources/win/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | 4 | #define IDR_MAINFRAME 1 5 | 6 | // Next default values for new objects 7 | // 8 | #ifdef APSTUDIO_INVOKED 9 | #ifndef APSTUDIO_READONLY_SYMBOLS 10 | #define _APS_NEXT_RESOURCE_VALUE 101 11 | #define _APS_NEXT_COMMAND_VALUE 40001 12 | #define _APS_NEXT_CONTROL_VALUE 1001 13 | #define _APS_NEXT_SYMED_VALUE 101 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /src/browser/resources/win/thrust_shell.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/breach/thrust/128210dffe10d6a0f5119c9fdfdded98f604feec/src/browser/resources/win/thrust_shell.ico -------------------------------------------------------------------------------- /src/browser/resources/win/thrust_shell.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "afxres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | 21 | #ifdef APSTUDIO_INVOKED 22 | ///////////////////////////////////////////////////////////////////////////// 23 | // 24 | // TEXTINCLUDE 25 | // 26 | 27 | 1 TEXTINCLUDE 28 | BEGIN 29 | "resource.h\0" 30 | END 31 | 32 | 2 TEXTINCLUDE 33 | BEGIN 34 | "#include ""afxres.h""\r\n" 35 | "\0" 36 | END 37 | 38 | 3 TEXTINCLUDE 39 | BEGIN 40 | "\r\n" 41 | "\0" 42 | END 43 | 44 | #endif // APSTUDIO_INVOKED 45 | 46 | 47 | ///////////////////////////////////////////////////////////////////////////// 48 | // 49 | // Version 50 | // 51 | 52 | VS_VERSION_INFO VERSIONINFO 53 | FILEVERSION 0,7,0,0 54 | PRODUCTVERSION 0,7,0,0 55 | FILEFLAGSMASK 0x3fL 56 | #ifdef _DEBUG 57 | FILEFLAGS 0x1L 58 | #else 59 | FILEFLAGS 0x0L 60 | #endif 61 | FILEOS 0x40004L 62 | FILETYPE 0x1L 63 | FILESUBTYPE 0x0L 64 | BEGIN 65 | BLOCK "StringFileInfo" 66 | BEGIN 67 | BLOCK "040904b0" 68 | BEGIN 69 | VALUE "CompanyName", "Breach" 70 | VALUE "FileDescription", "ThrustShell" 71 | VALUE "FileVersion", "0.7.0" 72 | VALUE "InternalName", "thrust_shell.exe" 73 | VALUE "LegalCopyright", "Copyright (C) 2014 Stanislas Polu. All rights reserved." 74 | VALUE "OriginalFilename", "thrust_shell.exe" 75 | VALUE "ProductName", "ThrustShell" 76 | VALUE "ProductVersion", "0.1.0" 77 | END 78 | END 79 | BLOCK "VarFileInfo" 80 | BEGIN 81 | VALUE "Translation", 0x409, 1200 82 | END 83 | END 84 | 85 | #endif // English (United States) resources 86 | ///////////////////////////////////////////////////////////////////////////// 87 | 88 | 89 | 90 | #ifndef APSTUDIO_INVOKED 91 | ///////////////////////////////////////////////////////////////////////////// 92 | // 93 | // Generated from the TEXTINCLUDE 3 resource. 94 | // 95 | 96 | 97 | ///////////////////////////////////////////////////////////////////////////// 98 | #endif // not APSTUDIO_INVOKED 99 | 100 | ///////////////////////////////////////////////////////////////////////////// 101 | // 102 | // Icon 103 | // 104 | 105 | IDR_MAINFRAME ICON "thrust_shell.ico" 106 | ///////////////////////////////////////////////////////////////////////////// 107 | 108 | -------------------------------------------------------------------------------- /src/browser/session/thrust_session_cookie_store.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_BROWSER_SESSION_THRUST_SESSION_COOKIE_STORE_H_ 5 | #define THRUST_SHELL_BROWSER_SESSION_THRUST_SESSION_COOKIE_STORE_H_ 6 | 7 | #include "net/cookies/cookie_monster.h" 8 | 9 | namespace thrust_shell { 10 | 11 | class ThrustSession; 12 | 13 | // ### ThrustSessionCookieStore 14 | // 15 | // The ThrustSessionCookieStore is a glue between the CookieMonster Delegate and 16 | // PersistentCookieStore interface and the ThrustSession JS API. It calls into 17 | // JS whenever it receives a call from the CookieMonster of which it is both 18 | // the Delegate and the PersistentCookieStore. 19 | // 20 | // The ThrustSessionCookieStore is RefCounted and therefore owned by the URLRequest 21 | // context that uses it. We also keep track of the parent ThrustSession to be able 22 | // to not call into its wrapper if it's been deleted (which should not happen in 23 | // theory) 24 | class ThrustSessionCookieStore : public net::CookieMonster::PersistentCookieStore { 25 | 26 | typedef net::CookieMonster::PersistentCookieStore::LoadedCallback 27 | LoadedCallback; 28 | 29 | public: 30 | // ### ThrustSessionCookieStore 31 | // We keep a pointer to the parent ThrustSession to call into the JS API 32 | ThrustSessionCookieStore(ThrustSession* parent, bool dummy = false); 33 | 34 | /****************************************************************************/ 35 | /* COOKIE MONSTER PERSISTENT STORE IMPLEMENTATION */ 36 | /****************************************************************************/ 37 | virtual void Load(const LoadedCallback& loaded_callback) OVERRIDE; 38 | 39 | virtual void LoadCookiesForKey( 40 | const std::string& key, 41 | const LoadedCallback& loaded_callback) OVERRIDE; 42 | 43 | virtual void Flush(const base::Closure& callback) OVERRIDE; 44 | 45 | virtual void AddCookie(const net::CanonicalCookie& cc) OVERRIDE; 46 | virtual void UpdateCookieAccessTime(const net::CanonicalCookie& cc) OVERRIDE; 47 | virtual void DeleteCookie(const net::CanonicalCookie& cc) OVERRIDE; 48 | 49 | virtual void SetForceKeepSessionState() OVERRIDE; 50 | 51 | private: 52 | virtual ~ThrustSessionCookieStore(); 53 | 54 | ThrustSession* parent_; 55 | bool dummy_; 56 | 57 | unsigned int op_count_; 58 | 59 | friend class ThrustSession; 60 | 61 | DISALLOW_COPY_AND_ASSIGN(ThrustSessionCookieStore); 62 | }; 63 | 64 | } // namespace thrust_shell 65 | 66 | #endif // THRUST_SHELL_BROWSER_SESSION_THRUST_SESSION_COOKIE_STORE_H_ 67 | -------------------------------------------------------------------------------- /src/browser/session/thrust_session_proxy_config_service.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_BROWSER_SESSION_THRUST_SESSION_PROXY_CONFIG_SERVICE_H_ 5 | #define THRUST_SHELL_BROWSER_SESSION_THRUST_SESSION_PROXY_CONFIG_SERVICE_H_ 6 | 7 | #include "base/memory/scoped_ptr.h" 8 | #include "base/observer_list.h" 9 | #include "net/proxy/proxy_config_service.h" 10 | 11 | namespace thrust_shell { 12 | 13 | class ThrustSession; 14 | 15 | // ### ThrustSessionProxyConfigService 16 | // 17 | // The ThrustSessionProxyConfigService is the glue between the system proxy 18 | // service and custom proxy rules set by the user for a given thrust_session. 19 | // This proxy service is passed as argument to the 20 | // ThrustShellURLRequestContextGetter to manage all proxy information. 21 | // 22 | // The ProxyConfigService expose two simple methods SetProxyString and 23 | // ClearProxyString to set or clear (return to system settings) the proxy rules 24 | // for all requests made for this session 25 | class ThrustSessionProxyConfigService : public net::ProxyConfigService { 26 | public: 27 | // ### THrustSessionProxyConfigService 28 | ThrustSessionProxyConfigService(ThrustSession* parent); 29 | ~ThrustSessionProxyConfigService(); 30 | 31 | /****************************************************************************/ 32 | /* PUBLIC API */ 33 | /****************************************************************************/ 34 | void SetProxyRules(std::string& rules); 35 | void ClearProxyRules(); 36 | 37 | /****************************************************************************/ 38 | /* PROXY CONFIG SERVICE IMPLEMENTATION */ 39 | /****************************************************************************/ 40 | virtual void AddObserver(Observer* observer) OVERRIDE; 41 | virtual void RemoveObserver(Observer* observer) OVERRIDE; 42 | 43 | virtual ConfigAvailability GetLatestProxyConfig( 44 | net::ProxyConfig* config) OVERRIDE; 45 | virtual void OnLazyPoll() OVERRIDE; 46 | 47 | private: 48 | ThrustSession* parent_; 49 | 50 | ObserverList observers_; 51 | scoped_ptr system_service_; 52 | scoped_ptr fixed_service_; 53 | 54 | friend class ThrustSession; 55 | 56 | DISALLOW_COPY_AND_ASSIGN(ThrustSessionProxyConfigService); 57 | }; 58 | 59 | } // namespace thrust_shell 60 | 61 | #endif // THRUST_SHELL_BROWSER_SESSION_THRUST_SESSION_PROXY_CONFIG_SERVICE_H_ 62 | -------------------------------------------------------------------------------- /src/browser/session/thrust_session_visitedlink_store.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // See the LICENSE file. 3 | // 4 | #include "src/browser/session/thrust_session_visitedlink_store.h" 5 | 6 | #include "url/gurl.h" 7 | #include "content/public/browser/browser_thread.h" 8 | 9 | #include "src/browser/session/thrust_session.h" 10 | #include "src/browser/visitedlink/visitedlink_master.h" 11 | 12 | using namespace content; 13 | 14 | namespace thrust_shell { 15 | 16 | ThrustSessionVisitedLinkStore::ThrustSessionVisitedLinkStore( 17 | ThrustSession* parent) 18 | : parent_(parent), 19 | visitedlink_master_(new visitedlink::VisitedLinkMaster( 20 | parent, this, !parent->IsOffTheRecord())) 21 | { 22 | } 23 | 24 | ThrustSessionVisitedLinkStore::~ThrustSessionVisitedLinkStore() 25 | { 26 | } 27 | 28 | bool 29 | ThrustSessionVisitedLinkStore::Init() 30 | { 31 | return visitedlink_master_->Init(); 32 | } 33 | 34 | void 35 | ThrustSessionVisitedLinkStore::Add( 36 | const std::string& url) 37 | { 38 | if(!parent_->IsOffTheRecord()) { 39 | visitedlink_master_->AddURL(GURL(url)); 40 | } 41 | } 42 | 43 | void 44 | ThrustSessionVisitedLinkStore::Clear() 45 | { 46 | visitedlink_master_->DeleteAllURLs(); 47 | } 48 | 49 | 50 | void 51 | ThrustSessionVisitedLinkStore::RebuildTable( 52 | const scoped_refptr& enumerator) 53 | { 54 | /* We return no URL as the master here. The master takes care of persisting */ 55 | /* the visited links, and this API is used in case of failure or when off */ 56 | /* the record. */ 57 | enumerator->OnComplete(true); 58 | } 59 | 60 | } // namespace thrust_shell 61 | -------------------------------------------------------------------------------- /src/browser/session/thrust_session_visitedlink_store.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_BROWSER_SESSION_THRUST_SESSION_VISITEDLINK_STORE_H_ 5 | #define THRUST_SHELL_BROWSER_SESSION_THRUST_SESSION_VISITEDLINK_STORE_H_ 6 | 7 | #include 8 | 9 | #include "base/memory/scoped_ptr.h" 10 | #include "src/browser/visitedlink/visitedlink_delegate.h" 11 | 12 | namespace visitedlink { 13 | class VisitedLinkMaster; 14 | } 15 | 16 | namespace thrust_shell { 17 | 18 | class ThrustSession; 19 | 20 | // ### ThrustSessionVisitedLinkStore 21 | // 22 | // The ThrustSessionVisitedLinkStore is a wrapper around the VisitedLinkMaster. 23 | // It is a VisitedLinkDelegate (but returns not visited link) as the master 24 | // already takes care of storing links on disk and read from it if the browser 25 | // context is not off the record. 26 | // TODO(spolu): Later on we may want to expose the delgate API to JS but this 27 | // is low priority as it does not bring that much value for now. 28 | class ThrustSessionVisitedLinkStore 29 | : public visitedlink::VisitedLinkDelegate, 30 | public base::RefCountedThreadSafe { 31 | public: 32 | // ### ThrustSessionVisitedLinkStore 33 | // We keep a pointer to the parent ThrustSession to call into the JS API 34 | ThrustSessionVisitedLinkStore(ThrustSession* parent); 35 | 36 | // ### Init 37 | // Initialiazes the VisitedLinkStore (underlying VisitedLinkMaster 38 | // initialization) 39 | bool Init(); 40 | 41 | // ### Add 42 | // Adds an URL to the VisitedLink Store (underlying visitedlink_master) 43 | // ``` 44 | // @url {string} the URL to add 45 | // ``` 46 | void Add(const std::string& url); 47 | 48 | // ### Clear 49 | // Clears all VisitedLinks and destroys the file system storage as well 50 | void Clear(); 51 | 52 | /****************************************************************************/ 53 | /* VISITED LINK DELEGATE IMPLEMENTATION */ 54 | /****************************************************************************/ 55 | virtual void RebuildTable( 56 | const scoped_refptr& enumerator) OVERRIDE; 57 | 58 | private: 59 | virtual ~ThrustSessionVisitedLinkStore(); 60 | 61 | ThrustSession* parent_; 62 | scoped_ptr visitedlink_master_; 63 | 64 | friend class ThrustSession; 65 | friend class base::RefCountedThreadSafe; 66 | 67 | DISALLOW_COPY_AND_ASSIGN(ThrustSessionVisitedLinkStore); 68 | }; 69 | 70 | } // namespace thrust_shell 71 | 72 | #endif // THRUST_SHELL_BROWSER_SESSION_THRUST_SESSION_VISITEDLINK_STORE_H_ 73 | -------------------------------------------------------------------------------- /src/browser/thrust_menu_mac.mm: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #import "src/browser/thrust_menu.h" 5 | 6 | #import "base/mac/scoped_nsobject.h" 7 | #import "base/strings/sys_string_conversions.h" 8 | 9 | #import "src/browser/ui/cocoa/menu_controller.h" 10 | #import "src/browser/thrust_window.h" 11 | 12 | namespace thrust_shell { 13 | 14 | static base::scoped_nsobject menu_controller_; 15 | 16 | void 17 | ThrustMenu::PlatformPopup(ThrustWindow* window) { 18 | base::scoped_nsobject menu_controller( 19 | [[ThrustShellMenuController alloc] initWithModel:model_.get()]); 20 | 21 | NSWindow* nswindow = window->GetNativeWindow(); 22 | content::WebContents* web_contents = window->GetWebContents(); 23 | 24 | // Fake out a context menu event. 25 | NSEvent* currentEvent = [NSApp currentEvent]; 26 | NSPoint position = [nswindow mouseLocationOutsideOfEventStream]; 27 | NSTimeInterval eventTime = [currentEvent timestamp]; 28 | NSEvent* clickEvent = [NSEvent mouseEventWithType:NSRightMouseDown 29 | location:position 30 | modifierFlags:NSRightMouseDownMask 31 | timestamp:eventTime 32 | windowNumber:[nswindow windowNumber] 33 | context:nil 34 | eventNumber:0 35 | clickCount:1 36 | pressure:1.0]; 37 | 38 | // Show the menu. 39 | [NSMenu popUpContextMenu:[menu_controller menu] 40 | withEvent:clickEvent 41 | forView:web_contents->GetContentNativeView()]; 42 | } 43 | 44 | void 45 | ThrustMenu::PlatformCleanup() 46 | { 47 | if(application_menu_ == this) { 48 | [NSApp setMainMenu: nil]; 49 | } 50 | } 51 | 52 | // static 53 | void 54 | ThrustMenu::PlatformSetApplicationMenu(ThrustMenu* menu) { 55 | base::scoped_nsobject menu_controller( 56 | [[ThrustShellMenuController alloc] initWithModel:menu->model_.get()]); 57 | [NSApp setMainMenu:[menu_controller menu]]; 58 | 59 | /* Ensure the menu_controller_ is destroyed after main menu is set. */ 60 | menu_controller.swap(menu_controller_); 61 | } 62 | 63 | // static 64 | void 65 | ThrustMenu::SendActionToFirstResponder(const std::string& action) { 66 | SEL selector = NSSelectorFromString(base::SysUTF8ToNSString(action)); 67 | [NSApp sendAction:selector to:nil from:[NSApp mainMenu]]; 68 | } 69 | 70 | } // namespace thrust_shell 71 | -------------------------------------------------------------------------------- /src/browser/thrust_menu_views.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // See the LICENSE file. 3 | 4 | #include "src/browser/thrust_menu.h" 5 | 6 | #include "ui/gfx/screen.h" 7 | #include "ui/views/controls/menu/menu_runner.h" 8 | 9 | #include "src/browser/thrust_window.h" 10 | 11 | using namespace content; 12 | 13 | namespace thrust_shell { 14 | 15 | void 16 | ThrustMenu::PlatformPopup( 17 | ThrustWindow* window) 18 | { 19 | gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint(); 20 | views::MenuRunner menu_runner( 21 | model(), 22 | views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS); 23 | ignore_result(menu_runner.RunMenuAt( 24 | window->window_.get(), 25 | NULL, 26 | gfx::Rect(cursor, gfx::Size()), 27 | views::MENU_ANCHOR_TOPLEFT, 28 | ui::MENU_SOURCE_MOUSE)); 29 | } 30 | 31 | void 32 | ThrustMenu::PlatformCleanup() 33 | { 34 | if(application_menu_ == this) { 35 | for (size_t i = 0; i < ThrustWindow::s_instances.size(); ++i) { 36 | ThrustWindow::s_instances[i]->DetachMenu(); 37 | } 38 | } 39 | } 40 | 41 | // static 42 | void 43 | ThrustMenu::PlatformSetApplicationMenu(ThrustMenu* menu) { 44 | for (size_t i = 0; i < ThrustWindow::s_instances.size(); ++i) { 45 | ThrustWindow::s_instances[i]->AttachMenu(menu->model_.get()); 46 | } 47 | } 48 | 49 | 50 | 51 | } // namespace thrust_shell 52 | -------------------------------------------------------------------------------- /src/browser/ui/accelerator_util.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2013 GitHub, Inc. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_UI_ACCELERATOR_UTIL_H_ 6 | #define THRUST_SHELL_BROWSER_UI_ACCELERATOR_UTIL_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "ui/base/accelerators/accelerator.h" 12 | 13 | namespace ui { 14 | class MenuModel; 15 | } 16 | 17 | namespace accelerator_util { 18 | 19 | typedef struct { int position; ui::MenuModel* model; } MenuItem; 20 | typedef std::map AcceleratorTable; 21 | 22 | // Parse a string as an accelerator. 23 | bool StringToAccelerator(const std::string& description, 24 | ui::Accelerator* accelerator); 25 | 26 | // Set platform accelerator for the Accelerator. 27 | void SetPlatformAccelerator(ui::Accelerator* accelerator); 28 | 29 | // Generate a table that contains memu model's accelerators and command ids. 30 | void GenerateAcceleratorTable(AcceleratorTable* table, ui::MenuModel* model); 31 | 32 | // Trigger command from the accelerators table. 33 | bool TriggerAcceleratorTableCommand(AcceleratorTable* table, 34 | const ui::Accelerator& accelerator); 35 | 36 | } // namespace accelerator_util 37 | 38 | #endif // THRUST_SHELL_BROWSER_UI_ACCELERATOR_UTIL_H_ 39 | -------------------------------------------------------------------------------- /src/browser/ui/accelerator_util_mac.mm: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2013 GitHub, Inc. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/ui/accelerator_util.h" 6 | 7 | #include "ui/base/accelerators/accelerator.h" 8 | #import "ui/base/accelerators/platform_accelerator_cocoa.h" 9 | #import "ui/events/keycodes/keyboard_code_conversion_mac.h" 10 | 11 | namespace accelerator_util { 12 | 13 | void SetPlatformAccelerator(ui::Accelerator* accelerator) { 14 | unichar character; 15 | unichar characterIgnoringModifiers; 16 | ui::MacKeyCodeForWindowsKeyCode(accelerator->key_code(), 17 | 0, 18 | &character, 19 | &characterIgnoringModifiers); 20 | NSString* characters = 21 | [[[NSString alloc] initWithCharacters:&character length:1] autorelease]; 22 | 23 | NSUInteger modifiers = 24 | (accelerator->IsCtrlDown() ? NSControlKeyMask : 0) | 25 | (accelerator->IsCmdDown() ? NSCommandKeyMask : 0) | 26 | (accelerator->IsAltDown() ? NSAlternateKeyMask : 0) | 27 | (accelerator->IsShiftDown() ? NSShiftKeyMask : 0); 28 | 29 | scoped_ptr platform_accelerator( 30 | new ui::PlatformAcceleratorCocoa(characters, modifiers)); 31 | accelerator->set_platform_accelerator(platform_accelerator.Pass()); 32 | } 33 | 34 | } // namespace accelerator_util 35 | -------------------------------------------------------------------------------- /src/browser/ui/accelerator_util_views.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2013 GitHub, Inc. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/ui/accelerator_util.h" 6 | 7 | #include "ui/base/accelerators/accelerator.h" 8 | 9 | namespace accelerator_util { 10 | 11 | void SetPlatformAccelerator(ui::Accelerator* accelerator) { 12 | } 13 | 14 | } // namespace accelerator_util 15 | -------------------------------------------------------------------------------- /src/browser/ui/cocoa/event_processing_window.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2014 GitHub, Inc. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_UI_COCOA_EVENT_PROCESSING_WINDOW_H_ 6 | #define THRUST_SHELL_BROWSER_UI_COCOA_EVENT_PROCESSING_WINDOW_H_ 7 | 8 | #import 9 | 10 | // Override NSWindow to access unhandled keyboard events (for command 11 | // processing); subclassing NSWindow is the only method to do 12 | // this. 13 | @interface EventProcessingWindow : NSWindow { 14 | @private 15 | BOOL redispatchingEvent_; 16 | BOOL eventHandled_; 17 | } 18 | 19 | // Sends a key event to |NSApp sendEvent:|, but also makes sure that it's not 20 | // short-circuited to the RWHV. This is used to send keyboard events to the menu 21 | // and the cmd-` handler if a keyboard event comes back unhandled from the 22 | // renderer. The event must be of type |NSKeyDown|, |NSKeyUp|, or 23 | // |NSFlagsChanged|. 24 | // Returns |YES| if |event| has been handled. 25 | - (BOOL)redispatchKeyEvent:(NSEvent*)event; 26 | 27 | - (BOOL)performKeyEquivalent:(NSEvent*)theEvent; 28 | @end 29 | 30 | #endif // THRUST_SHELL_BROWSER_UI_COCOA_EVENT_PROCESSING_WINDOW_H_ 31 | -------------------------------------------------------------------------------- /src/browser/ui/cocoa/menu_controller.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2014 GitHub, Inc. 3 | // Copyright (c) 2012 The Chromium Authors. 4 | // See the LICENSE file. 5 | 6 | #ifndef THRUST_SHELL_BROWSER_UI_COCOA_MENU_CONTROLLER_H_ 7 | #define THRUST_SHELL_BROWSER_UI_COCOA_MENU_CONTROLLER_H_ 8 | 9 | #import 10 | 11 | #import "base/mac/scoped_nsobject.h" 12 | #import "base/strings/string16.h" 13 | 14 | namespace ui { 15 | class MenuModel; 16 | } 17 | 18 | // A controller for the cross-platform menu model. The menu that's created 19 | // has the tag and represented object set for each menu item. The object is a 20 | // NSValue holding a pointer to the model for that level of the menu (to 21 | // allow for hierarchical menus). The tag is the index into that model for 22 | // that particular item. It is important that the model outlives this object 23 | // as it only maintains weak references. 24 | @interface ThrustShellMenuController : NSObject { 25 | @protected 26 | ui::MenuModel* model_; // weak 27 | base::scoped_nsobject menu_; 28 | BOOL isMenuOpen_; 29 | } 30 | 31 | @property(nonatomic, assign) ui::MenuModel* model; 32 | 33 | // NIB-based initializer. This does not create a menu. Clients can set the 34 | // properties of the object and the menu will be created upon the first call to 35 | // |-menu|. Note that the menu will be immutable after creation. 36 | - (id)init; 37 | 38 | // Builds a NSMenu from the pre-built model (must not be nil). Changes made 39 | // to the contents of the model after calling this will not be noticed. 40 | - (id)initWithModel:(ui::MenuModel*)model; 41 | 42 | // Programmatically close the constructed menu. 43 | - (void)cancel; 44 | 45 | // Access to the constructed menu if the complex initializer was used. If the 46 | // default initializer was used, then this will create the menu on first call. 47 | - (NSMenu*)menu; 48 | 49 | // Whether the menu is currently open. 50 | - (BOOL)isMenuOpen; 51 | 52 | // NSMenuDelegate methods this class implements. Subclasses should call super 53 | // if extending the behavior. 54 | - (void)menuWillOpen:(NSMenu*)menu; 55 | - (void)menuDidClose:(NSMenu*)menu; 56 | 57 | @end 58 | 59 | // Exposed only for unit testing, do not call directly. 60 | @interface ThrustShellMenuController (PrivateExposedForTesting) 61 | - (BOOL)validateUserInterfaceItem:(id)item; 62 | @end 63 | 64 | // Protected methods that subclassers can override. 65 | @interface ThrustShellMenuController (Protected) 66 | - (void)addItemToMenu:(NSMenu*)menu 67 | atIndex:(NSInteger)index 68 | fromModel:(ui::MenuModel*)model; 69 | - (NSMenu*)menuFromModel:(ui::MenuModel*)model; 70 | @end 71 | 72 | #endif // THRUST_SHELL_BROWSER_UI_COCOA_MENU_CONTROLLER_H_ 73 | -------------------------------------------------------------------------------- /src/browser/ui/views/frameless_view.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2014 GitHub, Inc. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_UI_VIEWS_FRAMELESS_VIEW_H_ 6 | #define THRUST_SHELL_BROWSER_UI_VIEWS_FRAMELESS_VIEW_H_ 7 | 8 | #include "ui/views/window/non_client_view.h" 9 | 10 | namespace views { 11 | class Widget; 12 | } 13 | 14 | namespace thrust_shell { 15 | 16 | class ThrustWindow; 17 | 18 | class FramelessView : public views::NonClientFrameView { 19 | public: 20 | FramelessView(); 21 | virtual ~FramelessView(); 22 | 23 | virtual void Init(ThrustWindow* window, views::Widget* frame); 24 | 25 | // Returns whether the |point| is on frameless window's resizing border. 26 | int ResizingBorderHitTest(const gfx::Point& point); 27 | 28 | protected: 29 | /****************************************************************************/ 30 | /* NONCLIENTFRAMEVIEWS IMPLEMENTATION */ 31 | /****************************************************************************/ 32 | virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; 33 | virtual gfx::Rect GetWindowBoundsForClientBounds( 34 | const gfx::Rect& client_bounds) const OVERRIDE; 35 | virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; 36 | virtual void GetWindowMask(const gfx::Size& size, 37 | gfx::Path* window_mask) OVERRIDE; 38 | virtual void ResetWindowControls() OVERRIDE; 39 | virtual void UpdateWindowIcon() OVERRIDE; 40 | virtual void UpdateWindowTitle() OVERRIDE; 41 | 42 | /****************************************************************************/ 43 | /* VIEW OVERRIDE */ 44 | /****************************************************************************/ 45 | virtual gfx::Size GetPreferredSize() const OVERRIDE; 46 | virtual gfx::Size GetMinimumSize() const OVERRIDE; 47 | virtual gfx::Size GetMaximumSize() const OVERRIDE; 48 | virtual const char* GetClassName() const OVERRIDE; 49 | 50 | // Not owned. 51 | ThrustWindow* window_; 52 | views::Widget* frame_; 53 | 54 | private: 55 | DISALLOW_COPY_AND_ASSIGN(FramelessView); 56 | }; 57 | 58 | } // namespace thrust_shell 59 | 60 | #endif // THRUST_SHELL_BROWSER_UI_VIEWS_FRAMELESS_VIEW_H_ 61 | -------------------------------------------------------------------------------- /src/browser/ui/views/global_menu_bar_registrar_x11.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2013 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_UI_VIEWS_GLOBAL_MENU_BAR_REGISTRAR_X11_H_ 6 | #define THRUST_SHELL_BROWSER_UI_VIEWS_GLOBAL_MENU_BAR_REGISTRAR_X11_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "base/basictypes.h" 13 | #include "base/memory/ref_counted.h" 14 | #include "base/memory/singleton.h" 15 | #include "ui/base/glib/glib_signal.h" 16 | 17 | // Advertises our menu bars to Unity. 18 | // 19 | // GlobalMenuBarX11 is responsible for managing the DbusmenuServer for each 20 | // XID. We need a separate object to own the dbus channel to 21 | // com.canonical.AppMenu.Registrar and to register/unregister the mapping 22 | // between a XID and the DbusmenuServer instance we are offering. 23 | class GlobalMenuBarRegistrarX11 { 24 | public: 25 | static GlobalMenuBarRegistrarX11* GetInstance(); 26 | 27 | void OnWindowMapped(unsigned long xid); 28 | void OnWindowUnmapped(unsigned long xid); 29 | 30 | private: 31 | friend struct DefaultSingletonTraits; 32 | 33 | GlobalMenuBarRegistrarX11(); 34 | ~GlobalMenuBarRegistrarX11(); 35 | 36 | // Sends the actual message. 37 | void RegisterXID(unsigned long xid); 38 | void UnregisterXID(unsigned long xid); 39 | 40 | CHROMEG_CALLBACK_1(GlobalMenuBarRegistrarX11, void, OnProxyCreated, 41 | GObject*, GAsyncResult*); 42 | CHROMEG_CALLBACK_1(GlobalMenuBarRegistrarX11, void, OnNameOwnerChanged, 43 | GObject*, GParamSpec*); 44 | 45 | GDBusProxy* registrar_proxy_; 46 | 47 | // Window XIDs which want to be registered, but haven't yet been because 48 | // we're waiting for the proxy to become available. 49 | std::set live_xids_; 50 | 51 | DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarRegistrarX11); 52 | }; 53 | 54 | #endif // THRUST_SHELL_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_REGISTRAR_X11_H_ 55 | -------------------------------------------------------------------------------- /src/browser/ui/views/global_menu_bar_x11.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2014 GitHub, Inc. All rights reserved. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_UI_VIEWS_GLOBAL_MENU_BAR_X11_H_ 6 | #define THRUST_SHELL_BROWSER_UI_VIEWS_GLOBAL_MENU_BAR_X11_H_ 7 | 8 | #include 9 | 10 | #include "base/basictypes.h" 11 | #include "base/compiler_specific.h" 12 | #include "ui/base/glib/glib_signal.h" 13 | #include "ui/gfx/native_widget_types.h" 14 | 15 | typedef struct _DbusmenuMenuitem DbusmenuMenuitem; 16 | typedef struct _DbusmenuServer DbusmenuServer; 17 | 18 | namespace ui { 19 | class Accelerator; 20 | class MenuModel; 21 | } 22 | 23 | namespace thrust_shell { 24 | 25 | class ThrustWindow; 26 | 27 | // Controls the Mac style menu bar on Unity. 28 | // 29 | // Unity has an Apple-like menu bar at the top of the screen that changes 30 | // depending on the active window. In the GTK port, we had a hidden GtkMenuBar 31 | // object in each GtkWindow which existed only to be scrapped by the 32 | // libdbusmenu-gtk code. Since we don't have GtkWindows anymore, we need to 33 | // interface directly with the lower level libdbusmenu-glib, which we 34 | // opportunistically dlopen() since not everyone is running Ubuntu. 35 | // 36 | // This class is like the chrome's corresponding one, but it generates the menu 37 | // from menu models instead, and it is also per-window specific. 38 | class GlobalMenuBarX11 { 39 | public: 40 | explicit GlobalMenuBarX11(ThrustWindow* window); 41 | virtual ~GlobalMenuBarX11(); 42 | 43 | // Creates the object path for DbusemenuServer which is attached to |xid|. 44 | static std::string GetPathForWindow(gfx::AcceleratedWidget xid); 45 | 46 | void SetMenu(ui::MenuModel* menu_model); 47 | bool IsServerStarted() const; 48 | 49 | private: 50 | // Creates a DbusmenuServer. 51 | void InitServer(gfx::AcceleratedWidget xid); 52 | 53 | // Create a menu from menu model. 54 | void BuildMenuFromModel(ui::MenuModel* model, DbusmenuMenuitem* parent); 55 | 56 | // Sets the accelerator for |item|. 57 | void RegisterAccelerator(DbusmenuMenuitem* item, 58 | const ui::Accelerator& accelerator); 59 | 60 | CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnItemActivated, DbusmenuMenuitem*, 61 | unsigned int); 62 | CHROMEG_CALLBACK_0(GlobalMenuBarX11, void, OnSubMenuShow, DbusmenuMenuitem*); 63 | 64 | ThrustWindow* window_; 65 | gfx::AcceleratedWidget xid_; 66 | 67 | DbusmenuServer* server_; 68 | 69 | DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarX11); 70 | }; 71 | 72 | } // namespace thrust_shell 73 | 74 | #endif // THRUST_SHELL_BROWSER_UI_VIEWS_GLOBAL_MENU_BAR_X11_H_ 75 | -------------------------------------------------------------------------------- /src/browser/ui/views/menu_bar.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2014 GitHub, Inc. All rights reserved. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_UI_VIEWS_MENU_BAR_H_ 6 | #define THRUST_SHELL_BROWSER_UI_VIEWS_MENU_BAR_H_ 7 | 8 | #include "ui/views/controls/button/button.h" 9 | #include "ui/views/controls/button/menu_button_listener.h" 10 | #include "ui/views/view.h" 11 | 12 | namespace ui { 13 | class MenuModel; 14 | } 15 | 16 | namespace views { 17 | class MenuButton; 18 | } 19 | 20 | namespace thrust_shell { 21 | 22 | class MenuDelegate; 23 | 24 | class MenuBar : public views::View, 25 | public views::ButtonListener, 26 | public views::MenuButtonListener { 27 | public: 28 | MenuBar(); 29 | virtual ~MenuBar(); 30 | 31 | // Replaces current menu with a new one. 32 | void SetMenu(ui::MenuModel* menu_model); 33 | 34 | // Shows underline under accelerators. 35 | void SetAcceleratorVisibility(bool visible); 36 | 37 | // Returns which submenu has accelerator |key|, -1 would be returned when 38 | // there is no matching submenu. 39 | int GetAcceleratorIndex(base::char16 key); 40 | 41 | // Shows the submenu whose accelerator is |key|. 42 | void ActivateAccelerator(base::char16 key); 43 | 44 | // Returns there are how many items in the root menu. 45 | int GetItemCount() const; 46 | 47 | // Get the menu under specified screen point. 48 | bool GetMenuButtonFromScreenPoint(const gfx::Point& point, 49 | ui::MenuModel** menu_model, 50 | views::MenuButton** button); 51 | 52 | protected: 53 | // views::View: 54 | virtual const char* GetClassName() const OVERRIDE; 55 | 56 | // views::ButtonListener: 57 | virtual void ButtonPressed(views::Button* sender, 58 | const ui::Event& event) OVERRIDE; 59 | 60 | // views::MenuButtonListener: 61 | virtual void OnMenuButtonClicked(views::View* source, 62 | const gfx::Point& point) OVERRIDE; 63 | 64 | private: 65 | SkColor background_color_; 66 | 67 | #if defined(USE_X11) 68 | SkColor enabled_color_; 69 | SkColor disabled_color_; 70 | SkColor highlight_color_; 71 | SkColor hover_color_; 72 | #endif 73 | 74 | ui::MenuModel* menu_model_; 75 | scoped_ptr menu_delegate_; 76 | 77 | DISALLOW_COPY_AND_ASSIGN(MenuBar); 78 | }; 79 | 80 | } // namespace thrust_shell 81 | 82 | #endif // THRUST_SHELL_BROWSER_UI_VIEWS_MENU_BAR_H_ 83 | -------------------------------------------------------------------------------- /src/browser/ui/views/menu_delegate.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2014 GitHub, Inc. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_UI_VIEWS_MENU_DELEGATE_H_ 6 | #define THRUST_SHELL_BROWSER_UI_VIEWS_MENU_DELEGATE_H_ 7 | 8 | #include 9 | 10 | #include "ui/views/controls/menu/menu_delegate.h" 11 | 12 | namespace views { 13 | class MenuModelAdapter; 14 | } 15 | 16 | namespace ui { 17 | class MenuModel; 18 | } 19 | 20 | namespace thrust_shell { 21 | 22 | class MenuBar; 23 | 24 | class MenuDelegate : public views::MenuDelegate { 25 | public: 26 | explicit MenuDelegate(MenuBar* menu_bar); 27 | virtual ~MenuDelegate(); 28 | 29 | void RunMenu(ui::MenuModel* model, views::MenuButton* button); 30 | 31 | protected: 32 | /****************************************************************************/ 33 | /* MENUDELEGATE IMPLEMENTATION */ 34 | /****************************************************************************/ 35 | virtual void ExecuteCommand(int id) OVERRIDE; 36 | virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE; 37 | virtual bool IsTriggerableEvent(views::MenuItemView* source, 38 | const ui::Event& e) OVERRIDE; 39 | virtual bool GetAccelerator(int id, 40 | ui::Accelerator* accelerator) const OVERRIDE; 41 | virtual base::string16 GetLabel(int id) const OVERRIDE; 42 | virtual const gfx::FontList* GetLabelFontList(int id) const OVERRIDE; 43 | virtual bool IsCommandEnabled(int id) const OVERRIDE; 44 | virtual bool IsItemChecked(int id) const OVERRIDE; 45 | virtual void SelectionChanged(views::MenuItemView* menu) OVERRIDE; 46 | virtual void WillShowMenu(views::MenuItemView* menu) OVERRIDE; 47 | virtual void WillHideMenu(views::MenuItemView* menu) OVERRIDE; 48 | virtual views::MenuItemView* GetSiblingMenu( 49 | views::MenuItemView* menu, 50 | const gfx::Point& screen_point, 51 | views::MenuAnchorPosition* anchor, 52 | bool* has_mnemonics, 53 | views::MenuButton** button); 54 | 55 | private: 56 | // Gets the cached menu item view from the model. 57 | views::MenuItemView* BuildMenu(ui::MenuModel* model); 58 | 59 | // Returns delegate for current item. 60 | views::MenuDelegate* delegate() const { return delegates_[id_]; } 61 | 62 | MenuBar* menu_bar_; 63 | 64 | // Current item's id. 65 | int id_; 66 | // Cached menu items, managed by MenuRunner. 67 | std::vector items_; 68 | // Cached menu delegates for each menu item, managed by us. 69 | std::vector delegates_; 70 | 71 | DISALLOW_COPY_AND_ASSIGN(MenuDelegate); 72 | }; 73 | 74 | } // namespace thrust_shell 75 | 76 | #endif // THRUST_SHELL_BROWSER_UI_VIEWS_MENU_DELEGATE_H_ 77 | -------------------------------------------------------------------------------- /src/browser/ui/views/menu_layout.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2014 GitHub, Inc. All rights reserved. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/ui/views/menu_layout.h" 6 | 7 | namespace thrust_shell { 8 | 9 | MenuLayout::MenuLayout( 10 | int menu_height) 11 | : menu_height_(menu_height) 12 | { 13 | } 14 | 15 | MenuLayout::~MenuLayout() 16 | { 17 | } 18 | 19 | void 20 | MenuLayout::Layout( 21 | views::View* host) 22 | { 23 | if (!HasMenu(host)) { 24 | views::FillLayout::Layout(host); 25 | return; 26 | } 27 | 28 | gfx::Size size = host->GetContentsBounds().size(); 29 | gfx::Rect menu_Bar_bounds = gfx::Rect(0, 0, size.width(), menu_height_); 30 | gfx::Rect web_view_bounds = gfx::Rect( 31 | 0, menu_height_, size.width(), size.height() - menu_height_); 32 | 33 | views::View* web_view = host->child_at(0); 34 | views::View* menu_bar = host->child_at(1); 35 | web_view->SetBoundsRect(web_view_bounds); 36 | menu_bar->SetBoundsRect(menu_Bar_bounds); 37 | } 38 | 39 | gfx::Size 40 | MenuLayout::GetPreferredSize( 41 | const views::View* host) const 42 | { 43 | gfx::Size size = views::FillLayout::GetPreferredSize(host); 44 | if (!HasMenu(host)) 45 | return size; 46 | 47 | size.set_height(size.height() + menu_height_); 48 | return size; 49 | } 50 | 51 | int 52 | MenuLayout::GetPreferredHeightForWidth( 53 | const views::View* host, 54 | int width) const 55 | { 56 | int height = views::FillLayout::GetPreferredHeightForWidth(host, width); 57 | if (!HasMenu(host)) 58 | return height; 59 | 60 | return height + menu_height_; 61 | } 62 | 63 | bool 64 | MenuLayout::HasMenu( 65 | const views::View* host) const 66 | { 67 | return host->child_count() == 2; 68 | } 69 | 70 | } // namespace thrust_shell 71 | -------------------------------------------------------------------------------- /src/browser/ui/views/menu_layout.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2014 GitHub, Inc. All rights reserved. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_UI_VIEWS_MENU_LAYOUT_H_ 6 | #define THRUST_SHELL_BROWSER_UI_VIEWS_MENU_LAYOUT_H_ 7 | 8 | #include "ui/views/layout/fill_layout.h" 9 | 10 | namespace thrust_shell { 11 | 12 | class MenuLayout : public views::FillLayout { 13 | public: 14 | explicit MenuLayout(int menu_height); 15 | virtual ~MenuLayout(); 16 | 17 | /****************************************************************************/ 18 | /* LAYOUTMANAGER IMPLEMENTATION */ 19 | /****************************************************************************/ 20 | virtual void Layout(views::View* host) OVERRIDE; 21 | virtual gfx::Size GetPreferredSize(const views::View* host) const OVERRIDE; 22 | virtual int GetPreferredHeightForWidth( 23 | const views::View* host, int width) const OVERRIDE; 24 | 25 | private: 26 | bool HasMenu(const views::View* host) const; 27 | 28 | int menu_height_; 29 | 30 | DISALLOW_COPY_AND_ASSIGN(MenuLayout); 31 | }; 32 | 33 | } // namespace thrust_shell 34 | 35 | #endif // THRUST_SHELL_BROWSER_UI_VIEWS_MENU_LAYOUT_H_ 36 | -------------------------------------------------------------------------------- /src/browser/ui/views/submenu_button.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2014 GitHub, Inc. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_UI_VIEWS_SUBMENU_BUTTON_H_ 6 | #define THRUST_SHELL_BROWSER_UI_VIEWS_SUBMENU_BUTTON_H_ 7 | 8 | #include "ui/views/controls/button/menu_button.h" 9 | 10 | namespace thrust_shell { 11 | 12 | // Special button that used by menu bar to show submenus. 13 | class SubmenuButton : public views::MenuButton { 14 | public: 15 | SubmenuButton(views::ButtonListener* listener, 16 | const base::string16& title, 17 | views::MenuButtonListener* menu_button_listener); 18 | virtual ~SubmenuButton(); 19 | 20 | void SetAcceleratorVisibility(bool visible); 21 | void SetUnderlineColor(SkColor color); 22 | 23 | void SetEnabledColor(SkColor color); 24 | void SetBackgroundColor(SkColor color); 25 | 26 | base::char16 accelerator() const { return accelerator_; } 27 | 28 | /****************************************************************************/ 29 | /* MENUBUTTON IMPLEMENTATION */ 30 | /****************************************************************************/ 31 | virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 32 | 33 | private: 34 | bool GetUnderlinePosition(const base::string16& text, 35 | base::char16* accelerator, 36 | int* start, int* end); 37 | void GetCharacterPosition( 38 | const base::string16& text, int index, int* pos); 39 | 40 | base::char16 accelerator_; 41 | 42 | bool show_underline_; 43 | int underline_start_; 44 | int underline_end_; 45 | int text_width_; 46 | int text_height_; 47 | SkColor underline_color_; 48 | 49 | DISALLOW_COPY_AND_ASSIGN(SubmenuButton); 50 | }; 51 | 52 | } // namespace thrust_shell 53 | 54 | #endif // THRUST_SHELL_BROWSER_UI_VIEWS_SUBMENU_BUTTON_H_ 55 | -------------------------------------------------------------------------------- /src/browser/ui/views/win_frame_view.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2014 GitHub, Inc. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/ui/views/win_frame_view.h" 6 | 7 | #include "ui/gfx/win/dpi.h" 8 | #include "ui/views/widget/widget.h" 9 | #include "ui/views/win/hwnd_util.h" 10 | 11 | #include "src/browser/thrust_window.h" 12 | 13 | namespace thrust_shell { 14 | 15 | namespace { 16 | 17 | const char kViewClassName[] = "WinFrameView"; 18 | 19 | } // namespace 20 | 21 | 22 | WinFrameView::WinFrameView() 23 | { 24 | } 25 | 26 | WinFrameView::~WinFrameView() 27 | { 28 | } 29 | 30 | 31 | gfx::Rect 32 | WinFrameView::GetWindowBoundsForClientBounds( 33 | const gfx::Rect& client_bounds) const 34 | { 35 | gfx::Size size(client_bounds.size()); 36 | ClientAreaSizeToWindowSize(&size); 37 | return gfx::Rect(client_bounds.origin(), size); 38 | } 39 | 40 | int 41 | WinFrameView::NonClientHitTest( 42 | const gfx::Point& point) 43 | { 44 | if (window_->HasFrame()) 45 | return frame_->client_view()->NonClientHitTest(point); 46 | else 47 | return FramelessView::NonClientHitTest(point); 48 | } 49 | 50 | gfx::Size 51 | WinFrameView::GetMinimumSize() const 52 | { 53 | gfx::Size size = FramelessView::GetMinimumSize(); 54 | return gfx::win::DIPToScreenSize(size); 55 | } 56 | 57 | gfx::Size 58 | WinFrameView::GetMaximumSize() const 59 | { 60 | gfx::Size size = FramelessView::GetMaximumSize(); 61 | return gfx::win::DIPToScreenSize(size); 62 | } 63 | 64 | const char* 65 | WinFrameView::GetClassName() const 66 | { 67 | return kViewClassName; 68 | } 69 | 70 | void 71 | WinFrameView::ClientAreaSizeToWindowSize( 72 | gfx::Size* size) const 73 | { 74 | // AdjustWindowRect seems to return a wrong window size. 75 | gfx::Size window = frame_->GetWindowBoundsInScreen().size(); 76 | gfx::Size client = frame_->GetClientAreaBoundsInScreen().size(); 77 | size->set_width(size->width() + window.width() - client.width()); 78 | size->set_height(size->height() + window.height() - client.height()); 79 | } 80 | 81 | } // namespace thrust_shell 82 | -------------------------------------------------------------------------------- /src/browser/ui/views/win_frame_view.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2014 GitHub, Inc. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_UI_VIEWS_WIN_FRAME_VIEW_H_ 6 | #define THRUST_SHELL_BROWSER_UI_VIEWS_WIN_FRAME_VIEW_H_ 7 | 8 | #include "src/browser/ui/views/frameless_view.h" 9 | 10 | namespace thrust_shell { 11 | 12 | class WinFrameView : public FramelessView { 13 | public: 14 | WinFrameView(); 15 | virtual ~WinFrameView(); 16 | 17 | /****************************************************************************/ 18 | /* NONCLIENTFRAMEVIEW */ 19 | /****************************************************************************/ 20 | virtual gfx::Rect GetWindowBoundsForClientBounds( 21 | const gfx::Rect& client_bounds) const OVERRIDE; 22 | virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; 23 | 24 | /****************************************************************************/ 25 | /* VIEWS OVERRIDE */ 26 | /****************************************************************************/ 27 | virtual gfx::Size GetMinimumSize() const OVERRIDE; 28 | virtual gfx::Size GetMaximumSize() const OVERRIDE; 29 | virtual const char* GetClassName() const OVERRIDE; 30 | 31 | private: 32 | void ClientAreaSizeToWindowSize(gfx::Size* size) const; 33 | 34 | DISALLOW_COPY_AND_ASSIGN(WinFrameView); 35 | }; 36 | 37 | } // namespace thrust_shell 38 | 39 | #endif // THRUST_SHELL_BROWSER_UI_VIEWS_WIN_FRAME_VIEW_H_ 40 | -------------------------------------------------------------------------------- /src/browser/util/platform_util.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_UTIL_PLATFORM_UTIL_H_ 6 | #define THRUST_SHELL_BROWSER_UTIL_PLATFORM_UTIL_H_ 7 | 8 | #include 9 | 10 | #include "base/strings/string16.h" 11 | #include "ui/gfx/native_widget_types.h" 12 | 13 | class GURL; 14 | 15 | namespace base { 16 | class FilePath; 17 | } 18 | 19 | namespace platform_util { 20 | 21 | // Show the given file in a file manager. If possible, select the file. 22 | // Must be called from the UI thread. 23 | void ShowItemInFolder(const base::FilePath& full_path); 24 | 25 | // Open the given file in the desktop's default manner. 26 | // Must be called from the UI thread. 27 | void OpenItem(const base::FilePath& full_path); 28 | 29 | // Open the given external protocol URL in the desktop's default manner. 30 | // (For example, mailto: URLs in the default mail user agent.) 31 | void OpenExternal(const GURL& url); 32 | 33 | // Get the top level window for the native view. This can return NULL. 34 | gfx::NativeWindow GetTopLevel(gfx::NativeView view); 35 | 36 | // Get the direct parent of |view|, may return NULL. 37 | gfx::NativeView GetParent(gfx::NativeView view); 38 | 39 | // Returns true if |window| is the foreground top level window. 40 | bool IsWindowActive(gfx::NativeWindow window); 41 | 42 | // Activate the window, bringing it to the foreground top level. 43 | void ActivateWindow(gfx::NativeWindow window); 44 | 45 | // Returns true if the view is visible. The exact definition of this is 46 | // platform-specific, but it is generally not "visible to the user", rather 47 | // whether the view has the visible attribute set. 48 | bool IsVisible(gfx::NativeView view); 49 | 50 | #if defined(OS_MACOSX) 51 | // On 10.7+, back and forward swipe gestures can be triggered using a scroll 52 | // gesture, if enabled in System Preferences. This function returns true if 53 | // the feature is supported and enabled, and false otherwise. 54 | bool IsSwipeTrackingFromScrollEventsEnabled(); 55 | #endif 56 | 57 | } // platform_util 58 | 59 | #endif // THRUST_SHELL_BROWSER_UTIL_PLATFORM_UTIL_H_ 60 | -------------------------------------------------------------------------------- /src/browser/util/platform_util_aura.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/util/platform_util.h" 6 | 7 | #include "base/logging.h" 8 | #include "ui/aura/window.h" 9 | 10 | #if defined(USE_ASH) 11 | #include "ash/wm/window_util.h" 12 | #endif 13 | 14 | namespace platform_util { 15 | 16 | gfx::NativeWindow GetTopLevel(gfx::NativeView view) { 17 | return view->GetToplevelWindow(); 18 | } 19 | 20 | gfx::NativeView GetParent(gfx::NativeView view) { 21 | return view->parent(); 22 | } 23 | 24 | bool IsWindowActive(gfx::NativeWindow window) { 25 | #if defined(USE_ASH) 26 | return ash::wm::IsActiveWindow(window); 27 | #else 28 | NOTIMPLEMENTED(); 29 | return false; 30 | #endif 31 | } 32 | 33 | void ActivateWindow(gfx::NativeWindow window) { 34 | #if defined(USE_ASH) 35 | ash::wm::ActivateWindow(window); 36 | #else 37 | NOTIMPLEMENTED(); 38 | #endif 39 | } 40 | 41 | bool IsVisible(gfx::NativeView view) { 42 | return view->IsVisible(); 43 | } 44 | 45 | } // namespace platform_util 46 | -------------------------------------------------------------------------------- /src/browser/util/platform_util_linux.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/util/platform_util.h" 6 | 7 | #include "base/bind.h" 8 | #include "base/file_util.h" 9 | #include "base/process/kill.h" 10 | #include "base/process/launch.h" 11 | #include "base/strings/utf_string_conversions.h" 12 | #include "content/public/browser/browser_thread.h" 13 | #include "url/gurl.h" 14 | 15 | using content::BrowserThread; 16 | 17 | namespace { 18 | 19 | void XDGUtil(const std::string& util, const std::string& arg) { 20 | std::vector argv; 21 | argv.push_back(util); 22 | argv.push_back(arg); 23 | 24 | base::LaunchOptions options; 25 | // xdg-open can fall back on mailcap which eventually might plumb through 26 | // to a command that needs a terminal. Set the environment variable telling 27 | // it that we definitely don't have a terminal available and that it should 28 | // bring up a new terminal if necessary. See "man mailcap". 29 | options.environ["MM_NOTTTY"] = "1"; 30 | 31 | // In Google Chrome, we do not let GNOME's bug-buddy intercept our crashes. 32 | // However, we do not want this environment variable to propagate to external 33 | // applications. See http://crbug.com/24120 34 | char* disable_gnome_bug_buddy = getenv("GNOME_DISABLE_CRASH_DIALOG"); 35 | if (disable_gnome_bug_buddy && 36 | disable_gnome_bug_buddy == std::string("SET_BY_GOOGLE_CHROME")) 37 | options.environ["GNOME_DISABLE_CRASH_DIALOG"] = std::string(); 38 | 39 | base::ProcessHandle handle; 40 | if (base::LaunchProcess(argv, options, &handle)) 41 | base::EnsureProcessGetsReaped(handle); 42 | } 43 | 44 | void XDGOpen(const std::string& path) { 45 | XDGUtil("xdg-open", path); 46 | } 47 | 48 | void XDGEmail(const std::string& email) { 49 | XDGUtil("xdg-email", email); 50 | } 51 | 52 | // TODO(estade): It would be nice to be able to select the file in the file 53 | // manager, but that probably requires extending xdg-open. For now just 54 | // show the folder. 55 | void ShowItemInFolderOnFileThread(const base::FilePath& full_path) { 56 | base::FilePath dir = full_path.DirName(); 57 | if (!base::DirectoryExists(dir)) 58 | return; 59 | 60 | XDGOpen(dir.value()); 61 | } 62 | 63 | } // namespace 64 | 65 | namespace platform_util { 66 | 67 | void ShowItemInFolder(const base::FilePath& full_path) { 68 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 69 | BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 70 | base::Bind(&ShowItemInFolderOnFileThread, full_path)); 71 | } 72 | 73 | void OpenItem(const base::FilePath& full_path) { 74 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 75 | BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 76 | base::Bind(&XDGOpen, full_path.value())); 77 | } 78 | 79 | void OpenExternal(const GURL& url) { 80 | if (url.SchemeIs("mailto")) 81 | XDGEmail(url.spec()); 82 | else 83 | XDGOpen(url.spec()); 84 | } 85 | 86 | } // namespace platform_util 87 | -------------------------------------------------------------------------------- /src/browser/visitedlink/visitedlink_delegate.h: -------------------------------------------------------------------------------- 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 3 | // found in the LICENSE file. 4 | 5 | #ifndef COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_DELEGATE_H_ 6 | #define COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_DELEGATE_H_ 7 | 8 | #include "base/memory/ref_counted.h" 9 | 10 | class GURL; 11 | 12 | namespace content { 13 | class BrowserContext; 14 | } 15 | 16 | namespace visitedlink { 17 | 18 | // Delegate class that clients of VisitedLinkMaster must implement. 19 | class VisitedLinkDelegate { 20 | public: 21 | // See RebuildTable. 22 | class URLEnumerator : public base::RefCountedThreadSafe { 23 | public: 24 | // Call this with each URL to rebuild the table. 25 | virtual void OnURL(const GURL& url) = 0; 26 | 27 | // This must be called by Delegate after RebuildTable is called. |success| 28 | // indicates all URLs have been returned successfully. The URLEnumerator 29 | // object cannot be used by the delegate after this call. 30 | virtual void OnComplete(bool success) = 0; 31 | 32 | protected: 33 | virtual ~URLEnumerator() {} 34 | 35 | private: 36 | friend class base::RefCountedThreadSafe; 37 | }; 38 | 39 | // Delegate class is responsible for persisting the list of visited URLs 40 | // across browser runs. This is called by VisitedLinkMaster to repopulate 41 | // its internal table. Note that methods on enumerator can be called on any 42 | // thread but the delegate is responsible for synchronizating the calls. 43 | virtual void RebuildTable(const scoped_refptr& enumerator) = 0; 44 | 45 | protected: 46 | virtual ~VisitedLinkDelegate() {} 47 | }; 48 | 49 | } // namespace visitedlink 50 | 51 | #endif // COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_DELEGATE_H_ 52 | -------------------------------------------------------------------------------- /src/browser/visitedlink/visitedlink_event_listener.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_EVENT_LISTENER_H_ 6 | #define COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_EVENT_LISTENER_H_ 7 | 8 | #include 9 | 10 | #include "base/memory/linked_ptr.h" 11 | #include "base/timer/timer.h" 12 | #include "content/public/browser/notification_observer.h" 13 | #include "content/public/browser/notification_registrar.h" 14 | 15 | #include "src/browser/visitedlink/visitedlink_master.h" 16 | 17 | namespace base { 18 | class SharedMemory; 19 | } 20 | 21 | namespace content { 22 | class BrowserContext; 23 | } 24 | 25 | namespace visitedlink { 26 | 27 | class VisitedLinkUpdater; 28 | 29 | // VisitedLinkEventListener broadcasts link coloring database updates to all 30 | // processes. It also coalesces the updates to avoid excessive broadcasting of 31 | // messages to the renderers. 32 | class VisitedLinkEventListener : public VisitedLinkMaster::Listener, 33 | public content::NotificationObserver { 34 | public: 35 | VisitedLinkEventListener(VisitedLinkMaster* master, 36 | content::BrowserContext* browser_context); 37 | virtual ~VisitedLinkEventListener(); 38 | 39 | virtual void NewTable(base::SharedMemory* table_memory) OVERRIDE; 40 | virtual void Add(VisitedLinkMaster::Fingerprint fingerprint) OVERRIDE; 41 | virtual void Reset() OVERRIDE; 42 | 43 | private: 44 | void CommitVisitedLinks(); 45 | 46 | // content::NotificationObserver implementation. 47 | virtual void Observe(int type, 48 | const content::NotificationSource& source, 49 | const content::NotificationDetails& details) OVERRIDE; 50 | 51 | base::OneShotTimer coalesce_timer_; 52 | VisitedLinkCommon::Fingerprints pending_visited_links_; 53 | 54 | content::NotificationRegistrar registrar_; 55 | 56 | // Map between renderer child ids and their VisitedLinkUpdater. 57 | typedef std::map > Updaters; 58 | Updaters updaters_; 59 | 60 | VisitedLinkMaster* master_; 61 | 62 | // Used to filter RENDERER_PROCESS_CREATED notifications to renderers that 63 | // belong to this BrowserContext. 64 | content::BrowserContext* browser_context_; 65 | 66 | DISALLOW_COPY_AND_ASSIGN(VisitedLinkEventListener); 67 | }; 68 | 69 | } // namespace visitedlink 70 | 71 | #endif // COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_EVENT_LISTENER_H_ 72 | -------------------------------------------------------------------------------- /src/browser/web_view/web_view_constants.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "src/browser/web_view/web_view_constants.h" 6 | 7 | namespace webview { 8 | 9 | // Events types. 10 | const char kDidAttach[] = "did-attach"; 11 | const char kZoomChanged[] = "zoom-changed"; 12 | const char kDestroyed[] = "destroyed"; 13 | 14 | // Parameters/properties on events. 15 | const char kIsTopLevel[] = "isTopLevel"; 16 | const char kReason[] = "reason"; 17 | const char kUrl[] = "url"; 18 | 19 | // Initialization parameters. 20 | const char kParameterApi[] = "api"; 21 | const char kParameterInstanceId[] = "instanceId"; 22 | 23 | // Other. 24 | const int kInstanceIDNone = 0; 25 | const char kStoragePartitionId[] = "storagePartitionId"; 26 | 27 | } // namespace webview 28 | -------------------------------------------------------------------------------- /src/browser/web_view/web_view_constants.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2013 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | // Constants used for the WebView API. 6 | 7 | #ifndef THRUST_SHELL_BROWSER_WEBVIEW_WEBVIEW_CONSTANTS_H_ 8 | #define THRUST_SHELL_BROWSER_WEBVIEW_WEBVIEW_CONSTANTS_H_ 9 | 10 | namespace webview { 11 | 12 | 13 | // Events types. 14 | extern const char kDidAttach[]; 15 | extern const char kZoomChanged[]; 16 | extern const char kDestroyed[]; 17 | 18 | /* TODO(spolu): Finish and cleanup */ 19 | 20 | // Parameters/properties on events. 21 | extern const char kIsTopLevel[]; 22 | extern const char kReason[]; 23 | extern const char kUrl[]; 24 | 25 | // Initialization parameters. 26 | extern const char kParameterApi[]; 27 | extern const char kParameterInstanceId[]; 28 | 29 | // Other. 30 | extern const int kInstanceIDNone; 31 | extern const char kStoragePartitionId[]; 32 | 33 | } // namespace webview 34 | 35 | #endif // THRUST_SHELL_BROWSER_WEBVIEW_WEBVIEW_CONSTANTS_H_ 36 | -------------------------------------------------------------------------------- /src/browser/web_view/web_view_javascript_dialog_manager.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/browser/web_view/web_view_javascript_dialog_manager.h" 6 | 7 | #include "base/command_line.h" 8 | #include "base/logging.h" 9 | #include "base/strings/utf_string_conversions.h" 10 | #include "net/base/net_util.h" 11 | #include "content/public/browser/web_contents.h" 12 | 13 | #include "src/common/switches.h" 14 | #include "src/browser/web_view/web_view_guest.h" 15 | #include "src/browser/thrust_window.h" 16 | 17 | using namespace content; 18 | 19 | namespace { 20 | 21 | std::string JavaScriptMessageTypeToString( 22 | JavaScriptMessageType javascript_message_type) { 23 | switch (javascript_message_type) { 24 | case JAVASCRIPT_MESSAGE_TYPE_ALERT: 25 | return "alert"; 26 | case JAVASCRIPT_MESSAGE_TYPE_CONFIRM: 27 | return "confirm"; 28 | case JAVASCRIPT_MESSAGE_TYPE_PROMPT: 29 | return "prompt"; 30 | default: 31 | NOTREACHED() << "Unknown Javascript Message Type"; 32 | return "ignore"; 33 | } 34 | } 35 | 36 | } // namespace 37 | 38 | namespace thrust_shell { 39 | 40 | WebViewGuestJavaScriptDialogManager::WebViewGuestJavaScriptDialogManager( 41 | WebViewGuest* guest) 42 | : guest_(guest) 43 | { 44 | } 45 | 46 | WebViewGuestJavaScriptDialogManager::~WebViewGuestJavaScriptDialogManager() 47 | { 48 | } 49 | 50 | void 51 | WebViewGuestJavaScriptDialogManager::RunJavaScriptDialog( 52 | WebContents* web_contents, 53 | const GURL& origin_url, 54 | const std::string& accept_lang, 55 | JavaScriptMessageType javascript_message_type, 56 | const base::string16& message_text, 57 | const base::string16& default_prompt_text, 58 | const DialogClosedCallback& callback, 59 | bool* did_suppress_message) 60 | { 61 | if(!guest_) { 62 | *did_suppress_message = true; 63 | return; 64 | } 65 | 66 | dialog_callback_ = callback; 67 | 68 | base::DictionaryValue event; 69 | event.SetString("origin_url", origin_url.spec()); 70 | event.SetString("accept_lang", accept_lang); 71 | event.SetString("message_type", 72 | JavaScriptMessageTypeToString(javascript_message_type)); 73 | event.SetString("message_text", message_text); 74 | event.SetString("default_prompt_text", default_prompt_text); 75 | 76 | guest_->GetThrustWindow()->WebViewEmit( 77 | guest_->guest_instance_id_, 78 | "dialog", 79 | event); 80 | } 81 | 82 | void 83 | WebViewGuestJavaScriptDialogManager::RunBeforeUnloadDialog( 84 | WebContents* web_contents, 85 | const base::string16& message_text, 86 | bool is_reload, 87 | const DialogClosedCallback& callback) 88 | { 89 | callback.Run(true, base::string16()); 90 | } 91 | 92 | void 93 | WebViewGuestJavaScriptDialogManager::WebContentsDestroyed( 94 | content::WebContents* web_contents) 95 | { 96 | guest_ = NULL; 97 | } 98 | 99 | void 100 | WebViewGuestJavaScriptDialogManager::JavaScriptDialogClosed( 101 | bool success, 102 | const std::string& response) 103 | { 104 | if(!dialog_callback_.is_null()) { 105 | dialog_callback_.Run(success, base::UTF8ToUTF16(response)); 106 | dialog_callback_.Reset(); 107 | } 108 | } 109 | 110 | } // namespace thrust_shell 111 | -------------------------------------------------------------------------------- /src/browser/web_view/web_view_javascript_dialog_manager.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_BROWSER_WEB_VIEW_JAVASCRIPT_DIALOG_MANAGER_H_ 6 | #define THRUST_SHELL_BROWSER_WEB_VIEW_JAVASCRIPT_DIALOG_MANAGER_H_ 7 | 8 | #include "base/callback_forward.h" 9 | #include "base/compiler_specific.h" 10 | #include "base/memory/scoped_ptr.h" 11 | #include "content/public/browser/javascript_dialog_manager.h" 12 | 13 | namespace thrust_shell { 14 | 15 | class WebViewGuest; 16 | 17 | class WebViewGuestJavaScriptDialogManager : 18 | public content::JavaScriptDialogManager { 19 | public: 20 | WebViewGuestJavaScriptDialogManager(WebViewGuest* guest); 21 | virtual ~WebViewGuestJavaScriptDialogManager(); 22 | 23 | // JavaScriptDialogManager overrides 24 | virtual void RunJavaScriptDialog( 25 | content::WebContents* web_contents, 26 | const GURL& origin_url, 27 | const std::string& accept_lang, 28 | content::JavaScriptMessageType javascript_message_type, 29 | const base::string16& message_text, 30 | const base::string16& default_prompt_text, 31 | const DialogClosedCallback& callback, 32 | bool* did_suppress_message) OVERRIDE; 33 | 34 | virtual void RunBeforeUnloadDialog( 35 | content::WebContents* web_contents, 36 | const base::string16& message_text, 37 | bool is_reload, 38 | const DialogClosedCallback& callback) OVERRIDE; 39 | 40 | virtual void CancelActiveAndPendingDialogs( 41 | content::WebContents* web_contents) OVERRIDE {} 42 | 43 | virtual void WebContentsDestroyed( 44 | content::WebContents* web_contents) OVERRIDE; 45 | 46 | void JavaScriptDialogClosed(bool success, 47 | const std::string& response); 48 | 49 | private: 50 | WebViewGuest* guest_; 51 | //const content::DialogClosedCallback dialog_callback_; 52 | base::Callback dialog_callback_; 54 | 55 | DISALLOW_COPY_AND_ASSIGN(WebViewGuestJavaScriptDialogManager); 56 | }; 57 | 58 | } // namespace thrust_shell 59 | 60 | #endif // THRUST_SHELL_BROWSER_WEB_VIEW_JAVASCRIPT_DIALOG_MANAGER_H_ 61 | -------------------------------------------------------------------------------- /src/common/draggable_region.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/common/draggable_region.h" 6 | 7 | namespace thrust_shell { 8 | 9 | DraggableRegion::DraggableRegion() 10 | : draggable(false) { 11 | } 12 | 13 | } // namespace atom 14 | -------------------------------------------------------------------------------- /src/common/draggable_region.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_COMMON_DRAGGABLE_REGION_H_ 6 | #define THRUST_SHELL_COMMON_DRAGGABLE_REGION_H_ 7 | 8 | #include "ui/gfx/rect.h" 9 | 10 | namespace thrust_shell { 11 | 12 | struct DraggableRegion { 13 | bool draggable; 14 | gfx::Rect bounds; 15 | 16 | DraggableRegion(); 17 | }; 18 | 19 | } // namespace thrust_shell 20 | 21 | #endif // THRUST_SHELL_COMMON_DRAGGABLE_REGION_H_ 22 | -------------------------------------------------------------------------------- /src/common/messages.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | // Get basic type definitions. 6 | #define IPC_MESSAGE_IMPL 7 | #include "src/common/messages.h" 8 | 9 | // Generate constructors. 10 | #include "ipc/struct_constructor_macros.h" 11 | #include "src/common/messages.h" 12 | 13 | // Generate destructors. 14 | #include "ipc/struct_destructor_macros.h" 15 | #include "src/common/messages.h" 16 | 17 | // Generate param traits write methods. 18 | #include "ipc/param_traits_write_macros.h" 19 | namespace IPC { 20 | #include "src/common/messages.h" 21 | } // namespace IPC 22 | 23 | // Generate param traits read methods. 24 | #include "ipc/param_traits_read_macros.h" 25 | namespace IPC { 26 | #include "src/common/messages.h" 27 | } // namespace IPC 28 | 29 | // Generate param traits log methods. 30 | #include "ipc/param_traits_log_macros.h" 31 | namespace IPC { 32 | #include "src/common/messages.h" 33 | } // namespace IPC 34 | -------------------------------------------------------------------------------- /src/common/resources/mac/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleExecutable 6 | ThrustShell Framework 7 | CFBundleIdentifier 8 | org.breach.ThrustShellFramework 9 | CFBundleName 10 | ThrustShell Framework 11 | CFBundlePackageType 12 | FMWK 13 | NSSupportsAutomaticGraphicsSwitching 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/common/switches.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/common/switches.h" 6 | 7 | namespace switches { 8 | 9 | // Web runtime features. 10 | const char kExperimentalFeatures[] = "experimental-features"; 11 | const char kExperimentalCanvasFeatures[] = "experimental-canvas-features"; 12 | const char kSubpixelFontScaling[] = "subpixel-font-scaling"; 13 | const char kOverlayScrollbars[] = "overlay-scrollbars"; 14 | const char kOverlayFullscreenVideo[] = "overlay-fullscreen-video"; 15 | const char kSharedWorker[] = "shared-worker"; 16 | 17 | } // namespace switches 18 | -------------------------------------------------------------------------------- /src/common/switches.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | // Defines all the "thrust_shell" command-line switches. 6 | 7 | #ifndef THRUST_SHELL_COMMON_SWITCHES_H_ 8 | #define THRUST_SHELL_COMMON_SWITCHES_H_ 9 | 10 | namespace switches { 11 | 12 | extern const char kExperimentalFeatures[]; 13 | extern const char kExperimentalCanvasFeatures[]; 14 | extern const char kSubpixelFontScaling[]; 15 | extern const char kOverlayScrollbars[]; 16 | extern const char kOverlayFullscreenVideo[]; 17 | extern const char kSharedWorker[]; 18 | 19 | } // namespace switches 20 | 21 | #endif // THRUST_SHELL_COMMON_SWITCHES_H_ 22 | -------------------------------------------------------------------------------- /src/common/visitedlink/visitedlink_message_generator.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Get basic type definitions. 6 | #define IPC_MESSAGE_IMPL 7 | #include "src/common/visitedlink/visitedlink_message_generator.h" 8 | 9 | // Generate constructors. 10 | #include "ipc/struct_constructor_macros.h" 11 | #include "src/common/visitedlink/visitedlink_message_generator.h" 12 | 13 | // Generate destructors. 14 | #include "ipc/struct_destructor_macros.h" 15 | #include "src/common/visitedlink/visitedlink_message_generator.h" 16 | 17 | // Generate param traits write methods. 18 | #include "ipc/param_traits_write_macros.h" 19 | namespace IPC { 20 | #include "src/common/visitedlink/visitedlink_message_generator.h" 21 | } // namespace IPC 22 | 23 | // Generate param traits read methods. 24 | #include "ipc/param_traits_read_macros.h" 25 | namespace IPC { 26 | #include "src/common/visitedlink/visitedlink_message_generator.h" 27 | } // namespace IPC 28 | 29 | // Generate param traits log methods. 30 | #include "ipc/param_traits_log_macros.h" 31 | namespace IPC { 32 | #include "src/common/visitedlink/visitedlink_message_generator.h" 33 | } // namespace IPC 34 | 35 | -------------------------------------------------------------------------------- /src/common/visitedlink/visitedlink_message_generator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Multiply-included file, no traditional include guard. 6 | 7 | #include "src/common/visitedlink/visitedlink_messages.h" 8 | -------------------------------------------------------------------------------- /src/common/visitedlink/visitedlink_messages.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Multiply-included file, no traditional include guard. 6 | #include 7 | 8 | #include "base/basictypes.h" 9 | #include "base/memory/shared_memory.h" 10 | #include "content/public/common/common_param_traits_macros.h" 11 | #include "ipc/ipc_message_macros.h" 12 | 13 | #define IPC_MESSAGE_START VisitedLinkMsgStart 14 | 15 | // History system notification that the visited link database has been 16 | // replaced. It has one SharedMemoryHandle argument consisting of the table 17 | // handle. This handle is valid in the context of the renderer 18 | IPC_MESSAGE_CONTROL1(ChromeViewMsg_VisitedLink_NewTable, 19 | base::SharedMemoryHandle) 20 | 21 | // History system notification that a link has been added and the link 22 | // coloring state for the given hash must be re-calculated. 23 | IPC_MESSAGE_CONTROL1(ChromeViewMsg_VisitedLink_Add, std::vector) 24 | 25 | // History system notification that one or more history items have been 26 | // deleted, which at this point means that all link coloring state must be 27 | // re-calculated. 28 | IPC_MESSAGE_CONTROL0(ChromeViewMsg_VisitedLink_Reset) 29 | 30 | -------------------------------------------------------------------------------- /src/geolocation/access_token_store.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/geolocation/access_token_store.h" 6 | 7 | #include "base/bind.h" 8 | #include "base/message_loop/message_loop.h" 9 | #include "base/strings/utf_string_conversions.h" 10 | 11 | #include "src/browser/session/thrust_session.h" 12 | #include "src/browser/browser_client.h" 13 | 14 | #ifndef GOOGLEAPIS_API_KEY 15 | #define GOOGLEAPIS_API_KEY "AIzaSyAQfxPJiounkhOjODEO5ZieffeBv6yft2Q" 16 | #endif 17 | 18 | using namespace content; 19 | 20 | namespace thrust_shell { 21 | 22 | namespace { 23 | 24 | // Notice that we just combined the api key with the url together here, because 25 | // if we use the standard {url: key} format Chromium would override our key with 26 | // the predefined one in common.gypi of libchromiumcontent, which is empty. 27 | const char* kGeolocationProviderUrl = 28 | "https://www.googleapis.com/geolocation/v1/geolocate?key=" 29 | GOOGLEAPIS_API_KEY; 30 | 31 | } // namespace 32 | 33 | ThrustShellAccessTokenStore::ThrustShellAccessTokenStore() 34 | { 35 | } 36 | 37 | ThrustShellAccessTokenStore::~ThrustShellAccessTokenStore() 38 | { 39 | } 40 | 41 | void 42 | ThrustShellAccessTokenStore::LoadAccessTokens( 43 | const LoadAccessTokensCallbackType& callback) 44 | { 45 | AccessTokenSet access_token_set; 46 | 47 | // Equivelent to access_token_set[kGeolocationProviderUrl]. 48 | // Somehow base::string16 is causing compilation errors when used in a pair 49 | // of std::map on Linux, this can work around it. 50 | std::pair token_pair; 51 | token_pair.first = GURL(kGeolocationProviderUrl); 52 | access_token_set.insert(token_pair); 53 | 54 | callback.Run(access_token_set, 55 | ThrustShellBrowserClient::Get()->system_session()->url_request_context_getter()); 56 | } 57 | 58 | void ThrustShellAccessTokenStore::SaveAccessToken( 59 | const GURL& server_url, const base::string16& access_token) { 60 | LOG(INFO) << "ExoBrwoserAccessTokenStore::SaveAccessToken: " 61 | << server_url << " " 62 | << access_token; 63 | } 64 | 65 | } // namespace content 66 | -------------------------------------------------------------------------------- /src/geolocation/access_token_store.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_GEOLOCATION_ACCESS_TOKEN_STORE_H_ 6 | #define THRUST_SHELL_GEOLOCATION_ACCESS_TOKEN_STORE_H_ 7 | 8 | #include "base/memory/ref_counted.h" 9 | #include "content/public/browser/access_token_store.h" 10 | #include "net/url_request/url_request_context_getter.h" 11 | 12 | namespace thrust_shell { 13 | 14 | // Dummy access token store used to initialise the network location provider. 15 | class ThrustShellAccessTokenStore : public content::AccessTokenStore { 16 | public: 17 | explicit ThrustShellAccessTokenStore(); 18 | 19 | /****************************************************************************/ 20 | /* ACCESSTOKENSTORE IMPLEMENTATION */ 21 | /****************************************************************************/ 22 | virtual void LoadAccessTokens( 23 | const LoadAccessTokensCallbackType& callback) OVERRIDE; 24 | 25 | virtual void SaveAccessToken( 26 | const GURL& server_url, const base::string16& access_token) OVERRIDE; 27 | 28 | private: 29 | 30 | virtual ~ThrustShellAccessTokenStore(); 31 | 32 | DISALLOW_COPY_AND_ASSIGN(ThrustShellAccessTokenStore); 33 | }; 34 | 35 | } // namespace thrust_shell 36 | 37 | #endif // THRUST_SHELL_GEOLOCATION_ACCESS_TOKEN_STORE_H_ 38 | -------------------------------------------------------------------------------- /src/net/net_log.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/net/net_log.h" 6 | 7 | #include 8 | 9 | #include "base/command_line.h" 10 | #include "base/files/file_path.h" 11 | #include "base/values.h" 12 | #include "content/public/common/content_switches.h" 13 | #include "net/base/net_log_logger.h" 14 | 15 | namespace thrust_shell { 16 | 17 | namespace { 18 | 19 | base::DictionaryValue* 20 | GetThrustShellConstants() 21 | { 22 | base::DictionaryValue* constants_dict = net::NetLogLogger::GetConstants(); 23 | 24 | // Add a dictionary with client information 25 | base::DictionaryValue* dict = new base::DictionaryValue(); 26 | 27 | dict->SetString("name", "thrust_shell"); 28 | dict->SetString("command_line", 29 | CommandLine::ForCurrentProcess()->GetCommandLineString()); 30 | constants_dict->Set("clientInfo", dict); 31 | 32 | return constants_dict; 33 | } 34 | 35 | } // namespace 36 | 37 | ThrustShellNetLog::ThrustShellNetLog() 38 | { 39 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); 40 | 41 | if (command_line->HasSwitch(switches::kLogNetLog)) { 42 | base::FilePath log_path = 43 | command_line->GetSwitchValuePath(switches::kLogNetLog); 44 | // Much like logging.h, bypass threading restrictions by using fopen 45 | // directly. Have to write on a thread that's shutdown to handle events on 46 | // shutdown properly, and posting events to another thread as they occur 47 | // would result in an unbounded buffer size, so not much can be gained by 48 | // doing this on another thread. It's only used when debugging, so 49 | // performance is not a big concern. 50 | FILE* file = NULL; 51 | #if defined(OS_WIN) 52 | file = _wfopen(log_path.value().c_str(), L"w"); 53 | #elif defined(OS_POSIX) 54 | file = fopen(log_path.value().c_str(), "w"); 55 | #endif 56 | 57 | if (file == NULL) { 58 | LOG(ERROR) << "Could not open file " << log_path.value() 59 | << " for net logging"; 60 | } else { 61 | scoped_ptr constants(GetThrustShellConstants()); 62 | net_log_logger_.reset(new net::NetLogLogger(file, *constants)); 63 | net_log_logger_->StartObserving(this); 64 | } 65 | } 66 | } 67 | 68 | ThrustShellNetLog::~ThrustShellNetLog() 69 | { 70 | // Remove the observer we own before we're destroyed. 71 | if (net_log_logger_) 72 | RemoveThreadSafeObserver(net_log_logger_.get()); 73 | } 74 | 75 | } // namespace thrust_shell 76 | -------------------------------------------------------------------------------- /src/net/net_log.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_NET_NET_LOG_H_ 6 | #define THRUST_SHELL_NET_NET_LOG_H_ 7 | 8 | #include 9 | 10 | #include "base/memory/scoped_ptr.h" 11 | #include "net/base/net_log_logger.h" 12 | 13 | namespace thrust_shell { 14 | 15 | class ThrustShellNetLog : public net::NetLog { 16 | public: 17 | ThrustShellNetLog(); 18 | virtual ~ThrustShellNetLog(); 19 | 20 | private: 21 | scoped_ptr net_log_logger_; 22 | 23 | DISALLOW_COPY_AND_ASSIGN(ThrustShellNetLog); 24 | }; 25 | 26 | } // namespace thrust_shell 27 | 28 | #endif // THRUST_SHELL_NET_NET_LOG_H_ 29 | -------------------------------------------------------------------------------- /src/net/network_delegate.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_NET_NETWORK_DELEGATE_H_ 6 | #define THRUST_SHELL_NET_NETWORK_DELEGATE_H_ 7 | 8 | #include "base/basictypes.h" 9 | #include "base/compiler_specific.h" 10 | #include "net/base/network_delegate.h" 11 | 12 | namespace thrust_shell { 13 | 14 | class ThrustShellNetworkDelegate : public net::NetworkDelegate { 15 | public: 16 | ThrustShellNetworkDelegate(); 17 | virtual ~ThrustShellNetworkDelegate(); 18 | 19 | static void SetAcceptAllCookies(bool accept); 20 | 21 | private: 22 | /* net::NetworkDelegate implementation. */ 23 | virtual int OnBeforeURLRequest(net::URLRequest* request, 24 | const net::CompletionCallback& callback, 25 | GURL* new_url) OVERRIDE; 26 | virtual int OnBeforeSendHeaders(net::URLRequest* request, 27 | const net::CompletionCallback& callback, 28 | net::HttpRequestHeaders* headers) OVERRIDE; 29 | virtual void OnSendHeaders(net::URLRequest* request, 30 | const net::HttpRequestHeaders& headers) OVERRIDE; 31 | virtual int OnHeadersReceived( 32 | net::URLRequest* request, 33 | const net::CompletionCallback& callback, 34 | const net::HttpResponseHeaders* original_response_headers, 35 | scoped_refptr* 36 | override_response_headers, 37 | GURL* allowed_unsafe_redirect_url) OVERRIDE; 38 | virtual void OnBeforeRedirect(net::URLRequest* request, 39 | const GURL& new_location) OVERRIDE; 40 | virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; 41 | virtual void OnRawBytesRead(const net::URLRequest& request, 42 | int bytes_read) OVERRIDE; 43 | virtual void OnCompleted(net::URLRequest* request, bool started) OVERRIDE; 44 | virtual void OnURLRequestDestroyed(net::URLRequest* request) OVERRIDE; 45 | virtual void OnPACScriptError(int line_number, 46 | const base::string16& error) OVERRIDE; 47 | virtual AuthRequiredResponse OnAuthRequired( 48 | net::URLRequest* request, 49 | const net::AuthChallengeInfo& auth_info, 50 | const AuthCallback& callback, 51 | net::AuthCredentials* credentials) OVERRIDE; 52 | virtual bool OnCanGetCookies(const net::URLRequest& request, 53 | const net::CookieList& cookie_list) OVERRIDE; 54 | virtual bool OnCanSetCookie(const net::URLRequest& request, 55 | const std::string& cookie_line, 56 | net::CookieOptions* options) OVERRIDE; 57 | virtual bool OnCanAccessFile(const net::URLRequest& request, 58 | const base::FilePath& path) const OVERRIDE; 59 | virtual bool OnCanThrottleRequest( 60 | const net::URLRequest& request) const OVERRIDE; 61 | virtual int OnBeforeSocketStreamConnect( 62 | net::SocketStream* stream, 63 | const net::CompletionCallback& callback) OVERRIDE; 64 | 65 | DISALLOW_COPY_AND_ASSIGN(ThrustShellNetworkDelegate); 66 | }; 67 | 68 | } // namespace thrust_shell 69 | 70 | #endif // THRUST_SHELL_NET_NETWORK_DELEGATE_H_ 71 | -------------------------------------------------------------------------------- /src/net/url_request_context_getter.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. All rights reserved. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_NET_URL_REQUEST_CONTEXT_GETTER_H_ 6 | #define THRUST_SHELL_NET_URL_REQUEST_CONTEXT_GETTER_H_ 7 | 8 | #include "base/compiler_specific.h" 9 | #include "base/files/file_path.h" 10 | #include "base/memory/ref_counted.h" 11 | #include "base/memory/scoped_ptr.h" 12 | #include "content/public/browser/content_browser_client.h" 13 | #include "net/url_request/url_request_context_getter.h" 14 | #include "net/url_request/url_request_job_factory.h" 15 | 16 | namespace base { 17 | class MessageLoop; 18 | } 19 | 20 | namespace net { 21 | class HostResolver; 22 | class MappedHostResolver; 23 | class NetworkDelegate; 24 | class NetLog; 25 | class ProxyConfigService; 26 | class URLRequestContextStorage; 27 | } 28 | 29 | namespace thrust_shell { 30 | 31 | class ThrustSession; 32 | 33 | class ThrustShellURLRequestContextGetter : public net::URLRequestContextGetter { 34 | public: 35 | ThrustShellURLRequestContextGetter( 36 | ThrustSession* parent, 37 | bool ignore_certificate_errors, 38 | const base::FilePath& base_path, 39 | content::ProtocolHandlerMap* protocol_handlers, 40 | content::URLRequestInterceptorScopedVector request_interceptors, 41 | net::NetLog* net_log); 42 | 43 | // net::URLRequestContextGetter implementation. 44 | virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; 45 | virtual scoped_refptr 46 | GetNetworkTaskRunner() const OVERRIDE; 47 | 48 | net::HostResolver* host_resolver(); 49 | 50 | protected: 51 | virtual ~ThrustShellURLRequestContextGetter(); 52 | 53 | private: 54 | ThrustSession* parent_; 55 | bool ignore_certificate_errors_; 56 | base::FilePath base_path_; 57 | net::NetLog* net_log_; 58 | 59 | scoped_ptr network_delegate_; 60 | scoped_ptr storage_; 61 | scoped_ptr url_request_context_; 62 | content::ProtocolHandlerMap protocol_handlers_; 63 | content::URLRequestInterceptorScopedVector request_interceptors_; 64 | 65 | friend class ThrustSession; 66 | 67 | DISALLOW_COPY_AND_ASSIGN(ThrustShellURLRequestContextGetter); 68 | }; 69 | 70 | } // namespace thrust_shell 71 | 72 | #endif // THRUST_SHELL_NET_URL_REQUEST_CONTEXT_GETTER_H_ 73 | -------------------------------------------------------------------------------- /src/renderer/extensions/console.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef EXTENSIONS_RENDERER_CONSOLE_H_ 6 | #define EXTENSIONS_RENDERER_CONSOLE_H_ 7 | 8 | #include 9 | 10 | #include "content/public/common/console_message_level.h" 11 | #include "v8/include/v8.h" 12 | 13 | namespace content { 14 | class RenderView; 15 | } 16 | 17 | namespace extensions { 18 | 19 | // Utility for logging messages to RenderViews. 20 | namespace console { 21 | 22 | // Adds |message| to the console of |render_view| at various log levels. 23 | void Debug(content::RenderView* render_view, const std::string& message); 24 | void Log(content::RenderView* render_view, const std::string& message); 25 | void Warn(content::RenderView* render_view, const std::string& message); 26 | void Error(content::RenderView* render_view, const std::string& message); 27 | 28 | // Logs an Error then crashes the current process. 29 | void Fatal(content::RenderView* render_view, const std::string& message); 30 | 31 | void AddMessage(content::RenderView* render_view, 32 | content::ConsoleMessageLevel level, 33 | const std::string& message); 34 | 35 | // Adds |message| to the console that hosts |context|, if any. 36 | void Debug(v8::Handle context, const std::string& message); 37 | void Log(v8::Handle context, const std::string& message); 38 | void Warn(v8::Handle context, const std::string& message); 39 | void Error(v8::Handle context, const std::string& message); 40 | 41 | // Logs an Error then crashes the current process. 42 | void Fatal(v8::Handle context, const std::string& message); 43 | 44 | void AddMessage(v8::Handle context, 45 | content::ConsoleMessageLevel level, 46 | const std::string& message); 47 | 48 | // Returns a new v8::Object with each standard log method (Debug/Log/Warn/Error) 49 | // bound to respective debug/log/warn/error methods. This is a direct drop-in 50 | // replacement for the standard devtools console.* methods usually accessible 51 | // from JS. 52 | v8::Local AsV8Object(); 53 | 54 | } // namespace console 55 | 56 | } // namespace extensions 57 | 58 | #endif // EXTENSIONS_RENDERER_CONSOLE_H_ 59 | -------------------------------------------------------------------------------- /src/renderer/extensions/context.cc: -------------------------------------------------------------------------------- 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 3 | // found in the LICENSE file. 4 | 5 | #include "src/renderer/extensions/context.h" 6 | 7 | #include "base/logging.h" 8 | #include "base/memory/scoped_ptr.h" 9 | #include "base/strings/string_split.h" 10 | #include "base/values.h" 11 | #include "content/public/renderer/render_view.h" 12 | #include "content/public/renderer/v8_value_converter.h" 13 | #include "third_party/WebKit/public/web/WebFrame.h" 14 | #include "third_party/WebKit/public/web/WebDocument.h" 15 | #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" 16 | #include "third_party/WebKit/public/web/WebView.h" 17 | #include "v8/include/v8.h" 18 | 19 | #include "src/renderer/extensions/module_system.h" 20 | 21 | using content::V8ValueConverter; 22 | 23 | namespace extensions { 24 | 25 | Context::Context(v8::Handle v8_context, 26 | blink::WebFrame* web_frame) 27 | : v8_context_(v8_context), 28 | web_frame_(web_frame), 29 | safe_builtins_(this), 30 | isolate_(v8_context->GetIsolate()) { 31 | VLOG(1) << "Created context:\n" 32 | << " frame: " << web_frame_; 33 | } 34 | 35 | Context::~Context() { 36 | VLOG(1) << "Destroyed context:\n" 37 | << " frame: " << web_frame_; 38 | Invalidate(); 39 | } 40 | 41 | void Context::Invalidate() { 42 | if (!is_valid()) 43 | return; 44 | if (module_system_) 45 | module_system_->Invalidate(); 46 | web_frame_ = NULL; 47 | v8_context_.reset(); 48 | } 49 | 50 | content::RenderView* Context::GetRenderView() const { 51 | if (web_frame_ && web_frame_->view()) 52 | return content::RenderView::FromWebView(web_frame_->view()); 53 | else 54 | return NULL; 55 | } 56 | 57 | GURL Context::GetURL() const { 58 | /* TODO(spolu): Check OK */ 59 | /* see: user_script_slave.cc:216 */ 60 | return web_frame_ ? 61 | GURL(web_frame_->document().url().string()) : GURL(); 62 | } 63 | 64 | v8::Local Context::CallFunction( 65 | v8::Handle function, 66 | int argc, 67 | v8::Handle argv[]) const { 68 | v8::EscapableHandleScope handle_scope(isolate()); 69 | v8::Context::Scope scope(v8_context()); 70 | 71 | blink::WebScopedMicrotaskSuppression suppression; 72 | if (!is_valid()) { 73 | return handle_scope.Escape( 74 | v8::Local(v8::Undefined(isolate()))); 75 | } 76 | 77 | v8::Handle global = v8_context()->Global(); 78 | if (!web_frame_) 79 | return handle_scope.Escape(function->Call(global, argc, argv)); 80 | return handle_scope.Escape( 81 | v8::Local(web_frame_->callFunctionEvenIfScriptDisabled( 82 | function, global, argc, argv))); 83 | } 84 | 85 | } // namespace extensions 86 | -------------------------------------------------------------------------------- /src/renderer/extensions/document_bindings.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2013 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/renderer/extensions/document_bindings.h" 6 | 7 | #include 8 | 9 | #include "base/bind.h" 10 | #include "third_party/WebKit/public/web/WebDocument.h" 11 | #include "third_party/WebKit/public/web/WebFrame.h" 12 | #include "v8/include/v8.h" 13 | 14 | #include "src/renderer/extensions/script_context.h" 15 | 16 | namespace extensions { 17 | 18 | DocumentBindings::DocumentBindings( 19 | ScriptContext* context) 20 | : ObjectBackedNativeHandler(context) 21 | { 22 | RouteFunction("RegisterElement", 23 | base::Bind(&DocumentBindings::RegisterElement, 24 | base::Unretained(this))); 25 | } 26 | 27 | void 28 | DocumentBindings::RegisterElement( 29 | const v8::FunctionCallbackInfo& args) 30 | { 31 | if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsObject()) { 32 | NOTREACHED(); 33 | return; 34 | } 35 | 36 | std::string element_name(*v8::String::Utf8Value(args[0])); 37 | v8::Local options = args[1]->ToObject(); 38 | 39 | blink::WebExceptionCode ec = 0; 40 | blink::WebDocument document = context()->web_frame()->document(); 41 | 42 | v8::Handle constructor = 43 | document.registerEmbedderCustomElement( 44 | blink::WebString::fromUTF8(element_name), options, ec); 45 | args.GetReturnValue().Set(constructor); 46 | } 47 | 48 | } // namespace extensions 49 | -------------------------------------------------------------------------------- /src/renderer/extensions/document_bindings.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2013 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_RENDERER_EXTENSIONS_DOCUMENT_BINDINGS_H_ 6 | #define THRUST_SHELL_RENDERER_EXTENSIONS_DOCUMENT_BINDINGS_H_ 7 | 8 | #include "src/renderer/extensions/object_backed_native_handler.h" 9 | 10 | namespace extensions { 11 | 12 | class ScriptContext; 13 | 14 | class DocumentBindings : public ObjectBackedNativeHandler { 15 | public: 16 | // ### DocumentBindings 17 | DocumentBindings(ScriptContext* context); 18 | 19 | private: 20 | // ### RegisterElement 21 | // 22 | // Registers the provided element as a custom element in Blink. 23 | // ``` 24 | // @args {FunctionCallbackInfo} v8 args and return 25 | // ``` 26 | void RegisterElement(const v8::FunctionCallbackInfo& args); 27 | }; 28 | 29 | } // namespace extensions 30 | 31 | #endif // THRUST_SHELL_RENDERER_EXTENSIONS_DOCUMENT_BINDINGS_H_ 32 | -------------------------------------------------------------------------------- /src/renderer/extensions/local_source_map.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/renderer/extensions/local_source_map.h" 6 | 7 | #include "src/renderer/extensions/static_v8_external_string_resource.h" 8 | 9 | namespace extensions { 10 | 11 | LocalSourceMap::LocalSourceMap() 12 | { 13 | } 14 | 15 | LocalSourceMap::~LocalSourceMap() 16 | { 17 | } 18 | 19 | void LocalSourceMap::RegisterSource( 20 | const std::string& name, 21 | const std::string& source) 22 | { 23 | source_map_[name] = source; 24 | } 25 | 26 | v8::Handle 27 | LocalSourceMap::GetSource( 28 | v8::Isolate* isolate, 29 | const std::string& name) 30 | { 31 | if (!Contains(name)) 32 | return v8::Undefined(isolate); 33 | return ConvertString(isolate, source_map_[name]); 34 | } 35 | 36 | bool 37 | LocalSourceMap::Contains( 38 | const std::string& name) 39 | { 40 | return !!source_map_.count(name); 41 | } 42 | 43 | v8::Handle 44 | LocalSourceMap::ConvertString( 45 | v8::Isolate* isolate, 46 | const base::StringPiece& string) 47 | { 48 | // v8 takes ownership of the StaticV8ExternalAsciiStringResource (see 49 | // v8::String::NewExternal()). 50 | return v8::String::NewExternal( 51 | isolate, new StaticV8ExternalAsciiStringResource(string)); 52 | } 53 | 54 | } // namespace extensions 55 | -------------------------------------------------------------------------------- /src/renderer/extensions/local_source_map.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_RENDERER_EXTENSIONS_LOCAL_SOURCE_MAP_H_ 6 | #define THRUST_SHELL_RENDERER_EXTENSIONS_LOCAL_SOURCE_MAP_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "base/strings/string_piece.h" 12 | #include "v8/include/v8.h" 13 | 14 | #include "src/renderer/extensions/module_system.h" 15 | 16 | namespace extensions { 17 | 18 | class LocalSourceMap : public ModuleSystem::SourceMap { 19 | public: 20 | 21 | LocalSourceMap(); 22 | ~LocalSourceMap(); 23 | 24 | void RegisterSource(const std::string& name, const std::string& source); 25 | 26 | /****************************************************************************/ 27 | /* SOURCEMAP IMPLEMENTATION */ 28 | /****************************************************************************/ 29 | virtual v8::Handle GetSource(v8::Isolate* isolate, 30 | const std::string& name) OVERRIDE; 31 | virtual bool Contains(const std::string& name) OVERRIDE; 32 | 33 | private: 34 | v8::Handle ConvertString(v8::Isolate* isolate, 35 | const base::StringPiece& string); 36 | 37 | std::map source_map_; 38 | }; 39 | 40 | } // namespace extensions 41 | 42 | #endif // THRUST_SHELL_RENDERER_EXTENSIONS_LOCAL_SOURCE_MAP_H_ 43 | 44 | -------------------------------------------------------------------------------- /src/renderer/extensions/native_handler.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "src/renderer/extensions/native_handler.h" 6 | 7 | namespace extensions { 8 | 9 | NativeHandler::NativeHandler() : is_valid_(true) {} 10 | 11 | NativeHandler::~NativeHandler() {} 12 | 13 | void NativeHandler::Invalidate() { 14 | is_valid_ = false; 15 | } 16 | 17 | } // namespace extensions 18 | -------------------------------------------------------------------------------- /src/renderer/extensions/native_handler.h: -------------------------------------------------------------------------------- 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 3 | // found in the LICENSE file. 4 | 5 | #ifndef CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ 6 | #define CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ 7 | 8 | #include "base/basictypes.h" 9 | #include "v8/include/v8.h" 10 | 11 | namespace extensions { 12 | 13 | // NativeHandlers are intended to be used with a ModuleSystem. The ModuleSystem 14 | // will assume ownership of the NativeHandler, and as a ModuleSystem is tied to 15 | // a single v8::Context, this implies that NativeHandlers will also be tied to 16 | // a single v8::Context. 17 | // TODO(koz): Rename this to NativeJavaScriptModule. 18 | class NativeHandler { 19 | public: 20 | NativeHandler(); 21 | virtual ~NativeHandler(); 22 | 23 | // Create a new instance of the object this handler specifies. 24 | virtual v8::Handle NewInstance() = 0; 25 | 26 | // Invalidate this object so it cannot be used any more. This is needed 27 | // because it's possible for this to outlive its owner context. Invalidate 28 | // must be called before this happens. 29 | // 30 | // Subclasses should override to invalidate their own V8 state. If they do 31 | // they must call their superclass' Invalidate(). 32 | virtual void Invalidate(); 33 | 34 | protected: 35 | // Allow subclasses to query valid state. 36 | bool is_valid() { return is_valid_; } 37 | 38 | private: 39 | bool is_valid_; 40 | 41 | DISALLOW_COPY_AND_ASSIGN(NativeHandler); 42 | }; 43 | 44 | } // extensions 45 | 46 | #endif // CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ 47 | -------------------------------------------------------------------------------- /src/renderer/extensions/object_backed_native_handler.h: -------------------------------------------------------------------------------- 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 3 | // found in the LICENSE file. 4 | 5 | #ifndef CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_ 6 | #define CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "base/bind.h" 12 | #include "base/memory/linked_ptr.h" 13 | 14 | #include "src/renderer/extensions/native_handler.h" 15 | #include "src/renderer/extensions/scoped_persistent.h" 16 | 17 | #include "v8/include/v8-util.h" 18 | #include "v8/include/v8.h" 19 | 20 | namespace extensions { 21 | class ScriptContext; 22 | 23 | // An ObjectBackedNativeHandler is a factory for JS objects with functions on 24 | // them that map to native C++ functions. Subclasses should call RouteFunction() 25 | // in their constructor to define functions on the created JS objects. 26 | class ObjectBackedNativeHandler : public NativeHandler { 27 | public: 28 | explicit ObjectBackedNativeHandler(ScriptContext* context); 29 | virtual ~ObjectBackedNativeHandler(); 30 | 31 | // Create an object with bindings to the native functions defined through 32 | // RouteFunction(). 33 | virtual v8::Handle NewInstance() OVERRIDE; 34 | 35 | v8::Isolate* GetIsolate() const; 36 | 37 | protected: 38 | typedef base::Callback&)> 39 | HandlerFunction; 40 | 41 | // Installs a new 'route' from |name| to |handler_function|. This means that 42 | // NewInstance()s of this ObjectBackedNativeHandler will have a property 43 | // |name| which will be handled by |handler_function|. 44 | void RouteFunction(const std::string& name, 45 | const HandlerFunction& handler_function); 46 | 47 | ScriptContext* context() const { return context_; } 48 | 49 | virtual void Invalidate() OVERRIDE; 50 | 51 | private: 52 | // Callback for RouteFunction which routes the V8 call to the correct 53 | // base::Bound callback. 54 | static void Router(const v8::FunctionCallbackInfo& args); 55 | 56 | // When RouteFunction is called we create a v8::Object to hold the data we 57 | // need when handling it in Router() - this is the base::Bound function to 58 | // route to. 59 | // 60 | // We need a v8::Object because it's possible for v8 to outlive the 61 | // base::Bound function; the lifetime of an ObjectBackedNativeHandler is the 62 | // lifetime of webkit's involvement with it, not the life of the v8 context. 63 | // A scenario when v8 will outlive us is if a frame holds onto the 64 | // contentWindow of an iframe after it's removed. 65 | // 66 | // So, we use v8::Objects here to hold that data, effectively refcounting 67 | // the data. When |this| is destroyed we remove the base::Bound function from 68 | // the object to indicate that it shoudn't be called. 69 | typedef v8::PersistentValueVector RouterData; 70 | RouterData router_data_; 71 | 72 | ScriptContext* context_; 73 | 74 | ScopedPersistent object_template_; 75 | 76 | DISALLOW_COPY_AND_ASSIGN(ObjectBackedNativeHandler); 77 | }; 78 | 79 | } // namespace extensions 80 | 81 | #endif // CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_ 82 | -------------------------------------------------------------------------------- /src/renderer/extensions/remote_bindings.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_RENDERER_EXTENSIONS_REMOTE_BINDINGS_H_ 5 | #define THRUST_SHELL_RENDERER_EXTENSIONS_REMOTE_BINDINGS_H_ 6 | 7 | #include "base/values.h" 8 | 9 | #include "src/renderer/extensions/object_backed_native_handler.h" 10 | 11 | namespace thrust_shell { 12 | class ThrustShellRenderFrameObserver; 13 | } 14 | 15 | namespace extensions { 16 | 17 | class ScriptContext; 18 | 19 | class RemoteBindings : public ObjectBackedNativeHandler { 20 | public: 21 | // ### RemoteBindings 22 | RemoteBindings(ScriptContext* context); 23 | ~RemoteBindings(); 24 | 25 | // ### DispatchMessage 26 | // 27 | // Sends a message to the remote object to be dispatched any listener 28 | bool DispatchMessage(const base::DictionaryValue& message); 29 | 30 | private: 31 | 32 | // ### [RouteFunction] 33 | // 34 | // ``` 35 | // @args {FunctionCallbackInfo} v8 args and return 36 | // ``` 37 | void SendMessage(const v8::FunctionCallbackInfo& args); 38 | void SetHandler(const v8::FunctionCallbackInfo& args); 39 | 40 | v8::Persistent message_handler_; 41 | thrust_shell::ThrustShellRenderFrameObserver* render_frame_observer_; 42 | }; 43 | 44 | } // namespace extensions 45 | 46 | #endif // THRUST_SHELL_RENDERER_EXTENSIONS_REMOTE_BINDINGS_H_ 47 | -------------------------------------------------------------------------------- /src/renderer/extensions/resources/.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | -------------------------------------------------------------------------------- /src/renderer/extensions/resources/remote.js: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // See the LICENSE file. 3 | 4 | var RemoteNatives = requireNative('remote_natives'); 5 | 6 | var remote = function(spec, my) { 7 | my = my || {}; 8 | spec = spec || {}; 9 | 10 | my.listeners = []; 11 | 12 | // 13 | // _public_ 14 | // 15 | var send; /* send(message); */ 16 | var listen; /* listen(cb_); */ 17 | var remove; /* remove(cb_); */ 18 | 19 | // 20 | // _private_ 21 | // 22 | var handler; /* handler(message); */ 23 | 24 | // 25 | // #### _that_ 26 | // 27 | var that = {}; 28 | 29 | /****************************************************************************/ 30 | /* PRIVATE HELPERS */ 31 | /****************************************************************************/ 32 | // ### handler 33 | // 34 | // Handler for the RemoteNatives object 35 | // ``` 36 | // @msg {object} the message to dispatch 37 | // ``` 38 | handler = function(msg) { 39 | my.listeners.forEach(function(cb_) { 40 | return cb_(msg); 41 | }); 42 | }; 43 | 44 | /****************************************************************************/ 45 | /* REMOTE API */ 46 | /****************************************************************************/ 47 | // ### send 48 | // 49 | // Sends a remote message 50 | // ``` 51 | // @message {object} the message to send 52 | // ``` 53 | send = function(message) { 54 | if(typeof message !== 'object') { 55 | message = { payload: message }; 56 | } 57 | RemoteNatives.SendMessage(message); 58 | }; 59 | 60 | // ### listen 61 | // 62 | // Adds a listener for remote messages 63 | // ``` 64 | // @cb_ {function(message)} 65 | // ``` 66 | listen = function(cb_) { 67 | remove(cb_); 68 | my.listeners.push(cb_); 69 | }; 70 | 71 | // ### remove 72 | // 73 | // Removes a message listener 74 | // ``` 75 | // @cb_ {function(message)} 76 | // ``` 77 | remove = function(cb_) { 78 | for(var i = my.listeners.length - 1; i >= 0; i--) { 79 | if(my.listeners[i] === cb_) { 80 | my.listeners.splice(i, 1); 81 | } 82 | } 83 | }; 84 | 85 | RemoteNatives.SetHandler(handler); 86 | 87 | that.send = send; 88 | that.listen = listen; 89 | that.remove = remove; 90 | 91 | return that; 92 | }; 93 | 94 | /******************************************************************************/ 95 | /* API REGISTRATION */ 96 | /******************************************************************************/ 97 | window.THRUST = window.THRUST || {}; 98 | window.THRUST.remote = remote({}); 99 | 100 | // GOAL: window.remote.send({...}); 101 | // window.remote.listen(function(msg) {...}); 102 | // window.remote.remove(function(msg) {...}); 103 | 104 | /* TODO(spolu): 105 | // window.remote.emit('type', {...}) 106 | // window.remote.on('type', function(evt) {...}); 107 | // window.remote.expose('method', function(args, cb_) {...}); 108 | // window.remote.call('method', args, function(err, res) {...}); 109 | */ 110 | -------------------------------------------------------------------------------- /src/renderer/extensions/safe_builtins.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef CHROME_RENDERER_EXTENSIONS_SAFE_BUILTINS_H_ 6 | #define CHROME_RENDERER_EXTENSIONS_SAFE_BUILTINS_H_ 7 | 8 | #include "v8/include/v8.h" 9 | 10 | namespace extensions { 11 | class ScriptContext; 12 | 13 | // A collection of safe builtin objects, in that they won't be tained by 14 | // extensions overriding methods on them. 15 | class SafeBuiltins { 16 | public: 17 | // Creates the v8::Extension which manages SafeBuiltins instances. 18 | static v8::Extension* CreateV8Extension(); 19 | 20 | explicit SafeBuiltins(ScriptContext* context); 21 | 22 | virtual ~SafeBuiltins(); 23 | 24 | // Each method returns an object with methods taken from their respective 25 | // builtin object's prototype, adapted to automatically call() themselves. 26 | // 27 | // Examples: 28 | // Array.prototype.forEach.call(...) becomes Array.forEach(...) 29 | // Object.prototype.toString.call(...) becomes Object.toString(...) 30 | // Object.keys.call(...) becomes Object.keys(...) 31 | v8::Local GetArray() const; 32 | v8::Local GetFunction() const; 33 | v8::Local GetJSON() const; 34 | // NOTE(kalman): VS2010 won't compile "GetObject", it mysteriously renames it 35 | // to "GetObjectW" - hence GetObjekt. Sorry. 36 | v8::Local GetObjekt() const; 37 | v8::Local GetRegExp() const; 38 | v8::Local GetString() const; 39 | 40 | private: 41 | ScriptContext* context_; 42 | }; 43 | 44 | } // namespace extensions 45 | 46 | #endif // CHROME_RENDERER_EXTENSIONS_SAFE_BUILTINS_H_ 47 | -------------------------------------------------------------------------------- /src/renderer/extensions/scoped_persistent.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef CHROME_RENDERER_EXTENSIONS_SCOPED_PERSISTENT_H_ 6 | #define CHROME_RENDERER_EXTENSIONS_SCOPED_PERSISTENT_H_ 7 | 8 | #include "base/logging.h" 9 | #include "v8/include/v8.h" 10 | 11 | namespace extensions { 12 | 13 | // A v8::Persistent handle to a V8 value which destroys and clears the 14 | // underlying handle on destruction. 15 | template 16 | class ScopedPersistent { 17 | public: 18 | ScopedPersistent() { 19 | } 20 | 21 | explicit ScopedPersistent(v8::Handle handle) { 22 | reset(handle); 23 | } 24 | 25 | ~ScopedPersistent() { 26 | reset(); 27 | } 28 | 29 | void reset(v8::Handle handle) { 30 | if (!handle.IsEmpty()) 31 | handle_.Reset(GetIsolate(handle), handle); 32 | else 33 | reset(); 34 | } 35 | 36 | void reset() { 37 | handle_.Reset(); 38 | } 39 | 40 | bool IsEmpty() const { 41 | return handle_.IsEmpty(); 42 | } 43 | 44 | v8::Handle NewHandle() const { 45 | if (handle_.IsEmpty()) 46 | return v8::Local(); 47 | return v8::Local::New(GetIsolate(handle_), handle_); 48 | } 49 | 50 | v8::Handle NewHandle(v8::Isolate* isolate) const { 51 | if (handle_.IsEmpty()) 52 | return v8::Local(); 53 | return v8::Local::New(isolate, handle_); 54 | } 55 | 56 | template 57 | void SetWeak(P* parameters, 58 | typename v8::WeakCallbackData::Callback callback) { 59 | handle_.SetWeak(parameters, callback); 60 | } 61 | 62 | private: 63 | template 64 | static v8::Isolate* GetIsolate(v8::Handle object_handle) { 65 | // Only works for v8::Object and its subclasses. Add specialisations for 66 | // anything else. 67 | if (!object_handle.IsEmpty()) 68 | return GetIsolate(object_handle->CreationContext()); 69 | return v8::Isolate::GetCurrent(); 70 | } 71 | static v8::Isolate* GetIsolate(v8::Handle context_handle) { 72 | if (!context_handle.IsEmpty()) 73 | return context_handle->GetIsolate(); 74 | return v8::Isolate::GetCurrent(); 75 | } 76 | static v8::Isolate* GetIsolate( 77 | v8::Handle template_handle) { 78 | return v8::Isolate::GetCurrent(); 79 | } 80 | 81 | v8::Persistent handle_; 82 | 83 | DISALLOW_COPY_AND_ASSIGN(ScopedPersistent); 84 | }; 85 | 86 | } // namespace extensions 87 | 88 | #endif // CHROME_RENDERER_EXTENSIONS_SCOPED_PERSISTENT_H_ 89 | -------------------------------------------------------------------------------- /src/renderer/extensions/static_v8_external_string_resource.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "src/renderer/extensions/static_v8_external_string_resource.h" 6 | 7 | namespace extensions { 8 | 9 | StaticV8ExternalAsciiStringResource::StaticV8ExternalAsciiStringResource( 10 | const base::StringPiece& buffer) 11 | : buffer_(buffer) { 12 | } 13 | 14 | StaticV8ExternalAsciiStringResource::~StaticV8ExternalAsciiStringResource() { 15 | } 16 | 17 | const char* StaticV8ExternalAsciiStringResource::data() const { 18 | return buffer_.data(); 19 | } 20 | 21 | size_t StaticV8ExternalAsciiStringResource::length() const { 22 | return buffer_.length(); 23 | } 24 | 25 | } // namspace extensions 26 | -------------------------------------------------------------------------------- /src/renderer/extensions/static_v8_external_string_resource.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_RENDERER_EXTENSIONS_STATIC_V8_EXTERNAL_STRING_RESOURCE_H_ 6 | #define THRUST_SHELL_RENDERER_EXTENSIONS_STATIC_V8_EXTERNAL_STRING_RESOURCE_H_ 7 | 8 | #include "base/compiler_specific.h" 9 | #include "base/strings/string_piece.h" 10 | #include "v8/include/v8.h" 11 | 12 | namespace extensions { 13 | 14 | // A very simple implementation of v8::ExternalAsciiStringResource that just 15 | // wraps a buffer. The buffer must outlive the v8 runtime instance this resource 16 | // is used in. 17 | class StaticV8ExternalAsciiStringResource 18 | : public v8::String::ExternalAsciiStringResource { 19 | public: 20 | explicit StaticV8ExternalAsciiStringResource(const base::StringPiece& buffer); 21 | virtual ~StaticV8ExternalAsciiStringResource(); 22 | 23 | virtual const char* data() const OVERRIDE; 24 | virtual size_t length() const OVERRIDE; 25 | 26 | private: 27 | base::StringPiece buffer_; 28 | }; 29 | 30 | } // namspace extensions 31 | 32 | #endif // THRUST_SHELL_RENDERER_EXTENSIONS_STATIC_V8_EXTERNAL_STRING_RESOURCE_H_ 33 | -------------------------------------------------------------------------------- /src/renderer/extensions/unsafe_persistent.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef CHROME_RENDERER_EXTENSIONS_UNSAFE_PERSISTENT_H_ 6 | #define CHROME_RENDERER_EXTENSIONS_UNSAFE_PERSISTENT_H_ 7 | 8 | #include "v8/include/v8.h" 9 | 10 | namespace extensions { 11 | 12 | // An unsafe way to pass Persistent handles around. Do not use unless you know 13 | // what you're doing. UnsafePersistent is only safe to use when we know that the 14 | // memory pointed by it is not going away: 1) When GC cannot happen while the 15 | // UnsafePersistent is alive or 2) when there is a strong Persistent keeping the 16 | // memory alive while the UnsafePersistent is alive. 17 | template class UnsafePersistent { 18 | public: 19 | UnsafePersistent() : value_(0) { } 20 | 21 | explicit UnsafePersistent(v8::Persistent* handle) { 22 | value_ = handle->ClearAndLeak(); 23 | } 24 | 25 | UnsafePersistent(v8::Isolate* isolate, const v8::Handle& handle) { 26 | v8::Persistent persistent(isolate, handle); 27 | value_ = persistent.ClearAndLeak(); 28 | } 29 | 30 | // Usage of this function requires 31 | // V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR to be defined 32 | void dispose() { 33 | v8::Persistent handle(value_); 34 | handle.Reset(); 35 | value_ = 0; 36 | } 37 | 38 | // Usage of this function requires 39 | // V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR to be defined 40 | v8::Local newLocal(v8::Isolate* isolate) { 41 | return v8::Local::New(isolate, v8::Local(value_)); 42 | } 43 | 44 | private: 45 | T* value_; 46 | }; 47 | 48 | } // namespace extensions 49 | 50 | #endif // CHROME_RENDERER_EXTENSIONS_UNSAFE_PERSISTENT_H_ 51 | -------------------------------------------------------------------------------- /src/renderer/extensions/web_view_bindings.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_RENDERER_EXTENSIONS_WEB_VIEW_BINDINGS_H_ 5 | #define THRUST_SHELL_RENDERER_EXTENSIONS_WEB_VIEW_BINDINGS_H_ 6 | 7 | #include "base/values.h" 8 | 9 | #include "src/renderer/extensions/object_backed_native_handler.h" 10 | 11 | namespace thrust_shell { 12 | class ThrustShellRenderFrameObserver; 13 | } 14 | 15 | namespace extensions { 16 | 17 | class ScriptContext; 18 | 19 | class WebViewBindings : public ObjectBackedNativeHandler { 20 | public: 21 | // ### WebViewBindings 22 | WebViewBindings(ScriptContext* context); 23 | ~WebViewBindings(); 24 | 25 | // ### AttemptEmitEvent 26 | // 27 | // Attempts to emit an event for the given guest_instance_id. The event gets 28 | // emitted only if this WebViewBindings has an handler for it 29 | bool AttemptEmitEvent(int guest_instance_id, 30 | const std::string type, 31 | const base::DictionaryValue& event); 32 | 33 | private: 34 | 35 | // ### [RouteFunction] 36 | // 37 | // ``` 38 | // @args {FunctionCallbackInfo} v8 args and return 39 | // ``` 40 | void CreateGuest(const v8::FunctionCallbackInfo& args); 41 | void DestroyGuest(const v8::FunctionCallbackInfo& args); 42 | void SetEventHandler(const v8::FunctionCallbackInfo& args); 43 | void SetAutoSize(const v8::FunctionCallbackInfo& args); 44 | void Go(const v8::FunctionCallbackInfo& args); 45 | void LoadUrl(const v8::FunctionCallbackInfo& args); 46 | void Reload(const v8::FunctionCallbackInfo& args); 47 | void Stop(const v8::FunctionCallbackInfo& args); 48 | void SetZoom(const v8::FunctionCallbackInfo& args); 49 | void Find(const v8::FunctionCallbackInfo& args); 50 | void StopFinding(const v8::FunctionCallbackInfo& args); 51 | void InsertCSS(const v8::FunctionCallbackInfo& args); 52 | void ExecuteScript(const v8::FunctionCallbackInfo& args); 53 | void OpenDevTools(const v8::FunctionCallbackInfo& args); 54 | void CloseDevTools(const v8::FunctionCallbackInfo& args); 55 | void IsDevToolsOpened(const v8::FunctionCallbackInfo& args); 56 | void JavaScriptDialogClosed(const v8::FunctionCallbackInfo& args); 57 | 58 | 59 | std::map> > guest_handlers_; 61 | thrust_shell::ThrustShellRenderFrameObserver* render_frame_observer_; 62 | }; 63 | 64 | } // namespace extensions 65 | 66 | #endif // THRUST_SHELL_RENDERER_EXTENSIONS_WEB_VIEW_BINDINGS_H_ 67 | -------------------------------------------------------------------------------- /src/renderer/render_frame_observer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // See the LICENSE file. 3 | 4 | #ifndef THRUST_SHELL_RENDERER_RENDER_FRAME_OBSERVER_H_ 5 | #define THRUST_SHELL_RENDERER_RENDER_FRAME_OBSERVER_H_ 6 | 7 | #include 8 | 9 | #include "base/values.h" 10 | 11 | #include "content/public/renderer/render_frame_observer.h" 12 | 13 | namespace blink { 14 | class WebFrame; 15 | } 16 | 17 | namespace content { 18 | class RenderFrame; 19 | } 20 | 21 | namespace extensions { 22 | class WebViewBindings; 23 | class RemoteBindings; 24 | } 25 | 26 | namespace thrust_shell { 27 | 28 | class ThrustShellRenderFrameObserver : public content::RenderFrameObserver { 29 | public: 30 | explicit ThrustShellRenderFrameObserver(content::RenderFrame* render_frame); 31 | virtual ~ThrustShellRenderFrameObserver(); 32 | 33 | static ThrustShellRenderFrameObserver* 34 | FromRenderFrame(content::RenderFrame* render_frame); 35 | 36 | /****************************************************************************/ 37 | /* RENDERFRAMEOBSERVER IMPLEMENTATION */ 38 | /****************************************************************************/ 39 | virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 40 | 41 | /****************************************************************************/ 42 | /* WEBVIEW MESSAGE HANDLING */ 43 | /****************************************************************************/ 44 | void AddWebViewBindings(extensions::WebViewBindings* bindings); 45 | void RemoveWebViewBindings(extensions::WebViewBindings* bindings); 46 | 47 | void WebViewEmit(int guest_instance_id, 48 | const std::string type, 49 | const base::DictionaryValue& event); 50 | 51 | /****************************************************************************/ 52 | /* REMOTE MESSAGE HANDLING */ 53 | /****************************************************************************/ 54 | void AddRemoteBindings(extensions::RemoteBindings* bindings); 55 | void RemoveRemoteBindings(extensions::RemoteBindings* bindings); 56 | 57 | void RemoteDispatch(const base::DictionaryValue& message); 58 | 59 | private: 60 | // A static container of all the instances. 61 | static std::vector s_instances; 62 | 63 | std::vector web_view_bindings_; 64 | std::vector remote_bindings_; 65 | 66 | DISALLOW_COPY_AND_ASSIGN(ThrustShellRenderFrameObserver); 67 | }; 68 | 69 | } // namespace thrust_shell 70 | 71 | #endif // THRUST_SHELL_RENDERER_RENDER_FRAME_OBSERVER_H_ 72 | -------------------------------------------------------------------------------- /src/renderer/render_process_observer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_RENDERER_RENDER_PROCESS_OBSERVER_H_ 6 | #define THRUST_SHELL_RENDERER_RENDER_PROCESS_OBSERVER_H_ 7 | 8 | #include "base/basictypes.h" 9 | #include "base/compiler_specific.h" 10 | #include "base/files/file_path.h" 11 | #include "base/memory/scoped_ptr.h" 12 | #include "ipc/ipc_platform_file.h" 13 | #include "content/public/renderer/render_process_observer.h" 14 | 15 | namespace content { 16 | class RenderView; 17 | } 18 | 19 | namespace thrust_shell { 20 | 21 | class ThrustShellRenderProcessObserver : public content::RenderProcessObserver { 22 | public: 23 | static ThrustShellRenderProcessObserver* GetInstance(); 24 | 25 | ThrustShellRenderProcessObserver(); 26 | virtual ~ThrustShellRenderProcessObserver(); 27 | 28 | /****************************************************************************/ 29 | /* RENDERPROCESSOBSERVER IMPLEMENTATIO */ 30 | /****************************************************************************/ 31 | virtual void WebKitInitialized() OVERRIDE; 32 | virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; 33 | 34 | private: 35 | void EnableWebRuntimeFeatures(); 36 | 37 | DISALLOW_COPY_AND_ASSIGN(ThrustShellRenderProcessObserver); 38 | }; 39 | 40 | } // namespace thrust_shell 41 | 42 | #endif // THRUST_SHELL_RENDERER_RENDER_PROCESS_OBSERVER_H_ 43 | -------------------------------------------------------------------------------- /src/renderer/render_view_observer.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #include "src/renderer/render_view_observer.h" 6 | 7 | #include "base/command_line.h" 8 | #include "third_party/WebKit/public/web/WebView.h" 9 | #include "third_party/WebKit/public/web/WebFrame.h" 10 | #include "third_party/WebKit/public/web/WebDocument.h" 11 | #include "third_party/WebKit/public/web/WebDraggableRegion.h" 12 | #include "content/public/renderer/render_view.h" 13 | #include "content/public/renderer/render_view_observer.h" 14 | 15 | #include "src/common/draggable_region.h" 16 | #include "src/common/switches.h" 17 | #include "src/common/messages.h" 18 | 19 | using namespace content; 20 | 21 | namespace thrust_shell { 22 | 23 | ThrustShellRenderViewObserver::ThrustShellRenderViewObserver( 24 | RenderView* render_view) 25 | : RenderViewObserver(render_view) 26 | { 27 | } 28 | 29 | bool 30 | ThrustShellRenderViewObserver::OnMessageReceived( 31 | const IPC::Message& message) 32 | { 33 | bool handled = true; 34 | /* 35 | IPC_BEGIN_MESSAGE_MAP(ThrustShellRenderViewObserver, message) 36 | IPC_MESSAGE_UNHANDLED(handled = false) 37 | IPC_END_MESSAGE_MAP() 38 | */ 39 | handled = false; 40 | 41 | return handled; 42 | } 43 | 44 | void 45 | ThrustShellRenderViewObserver::DraggableRegionsChanged( 46 | blink::WebFrame* frame) 47 | { 48 | blink::WebVector webregions = 49 | frame->document().draggableRegions(); 50 | std::vector regions; 51 | for (size_t i = 0; i < webregions.size(); ++i) { 52 | DraggableRegion region; 53 | region.bounds = webregions[i].bounds; 54 | region.draggable = webregions[i].draggable; 55 | regions.push_back(region); 56 | } 57 | Send(new ThrustViewHostMsg_UpdateDraggableRegions(routing_id(), regions)); 58 | } 59 | 60 | } // namespace thrust_shell 61 | -------------------------------------------------------------------------------- /src/renderer/render_view_observer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_RENDERER_RENDER_VIEW_OBSERVER_H_ 6 | #define THRUST_SHELL_RENDERER_RENDER_VIEW_OBSERVER_H_ 7 | 8 | #include "content/public/renderer/render_view_observer.h" 9 | 10 | namespace blink { 11 | class WebFrame; 12 | } 13 | 14 | namespace content { 15 | class RenderView; 16 | } 17 | 18 | namespace thrust_shell { 19 | 20 | class ThrustShellRenderViewObserver : public content::RenderViewObserver { 21 | public: 22 | explicit ThrustShellRenderViewObserver(content::RenderView* render_view); 23 | virtual ~ThrustShellRenderViewObserver() {} 24 | 25 | private: 26 | /****************************************************************************/ 27 | /* RENDERVIEWOBSERVER IMPLEMENTATION */ 28 | /****************************************************************************/ 29 | virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 30 | virtual void DraggableRegionsChanged(blink::WebFrame* frame) OVERRIDE; 31 | 32 | DISALLOW_COPY_AND_ASSIGN(ThrustShellRenderViewObserver); 33 | }; 34 | 35 | } // namespace thrust_shell 36 | 37 | #endif // THRUST_SHELL_RENDERER_RENDER_VIEW_OBSERVER_H_ 38 | -------------------------------------------------------------------------------- /src/renderer/renderer_client.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Stanislas Polu. 2 | // Copyright (c) 2012 The Chromium Authors. 3 | // See the LICENSE file. 4 | 5 | #ifndef THRUST_SHELL_RENDERER_CONTENT_RENDERER_CLIENT_H_ 6 | #define THRUST_SHELL_RENDERER_CONTENT_RENDERER_CLIENT_H_ 7 | 8 | #include "base/compiler_specific.h" 9 | #include "base/memory/scoped_ptr.h" 10 | #include "content/public/renderer/content_renderer_client.h" 11 | 12 | #include "src/renderer/extensions/local_source_map.h" 13 | 14 | namespace visitedlink { 15 | class VisitedLinkSlave; 16 | } 17 | 18 | namespace blink { 19 | class WebLocalFrame; 20 | class WebFrame; 21 | class WebPlugin; 22 | class WebPluginContainer; 23 | struct WebPluginParams; 24 | } 25 | 26 | namespace base { 27 | class DictionaryValue; 28 | class ListValue; 29 | } 30 | 31 | namespace thrust_shell { 32 | 33 | class ThrustShellRenderProcessObserver; 34 | class Dispatcher; 35 | 36 | class ThrustShellRendererClient : public content::ContentRendererClient { 37 | public: 38 | static ThrustShellRendererClient* Get(); 39 | 40 | ThrustShellRendererClient(); 41 | virtual ~ThrustShellRendererClient(); 42 | 43 | /****************************************************************************/ 44 | /* CONTENTRENDERERCLIENT IMPLEMENTATION */ 45 | /****************************************************************************/ 46 | virtual void RenderThreadStarted() OVERRIDE; 47 | virtual void RenderViewCreated(content::RenderView* render_view) OVERRIDE; 48 | virtual void RenderFrameCreated(content::RenderFrame* render_frame) OVERRIDE; 49 | 50 | virtual bool OverrideCreatePlugin( 51 | content::RenderFrame* render_frame, 52 | blink::WebLocalFrame* frame, 53 | const blink::WebPluginParams& params, 54 | blink::WebPlugin** plugin) OVERRIDE; 55 | 56 | virtual void DidCreateScriptContext( 57 | blink::WebFrame* frame, 58 | v8::Handle context, 59 | int extension_group, 60 | int world_id) OVERRIDE; 61 | bool ShouldFork(blink::WebFrame* frame, 62 | const GURL& url, 63 | const std::string& http_method, 64 | bool is_initial_navigation, 65 | bool is_server_redirect, 66 | bool* send_referrer) OVERRIDE; 67 | 68 | virtual unsigned long long VisitedLinkHash(const char* canonical_url, 69 | size_t length) OVERRIDE; 70 | virtual bool IsLinkVisited(unsigned long long link_hash) OVERRIDE; 71 | 72 | 73 | private: 74 | scoped_ptr observer_; 75 | scoped_ptr visited_link_slave_; 76 | extensions::LocalSourceMap source_map_; 77 | }; 78 | 79 | } // namespace thrust_shell 80 | 81 | #endif // THRUST_SHELL_RENDERER_CONTENT_RENDERER_CLIENT_H_ 82 | -------------------------------------------------------------------------------- /src/renderer/resources/mac/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleIdentifier 6 | org.breach.${PRODUCT_NAME}.helper 7 | CFBundleName 8 | ${PRODUCT_NAME} 9 | CFBundlePackageType 10 | APPL 11 | LSUIElement 12 | 13 | NSSupportsAutomaticGraphicsSwitching 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/renderer/visitedlink/visitedlink_slave.cc: -------------------------------------------------------------------------------- 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 3 | // found in the LICENSE file. 4 | 5 | #include "src/renderer/visitedlink/visitedlink_slave.h" 6 | 7 | #include "base/logging.h" 8 | #include "base/memory/shared_memory.h" 9 | #include "third_party/WebKit/public/web/WebView.h" 10 | 11 | #include "src/common/visitedlink/visitedlink_messages.h" 12 | 13 | using blink::WebView; 14 | 15 | namespace visitedlink { 16 | 17 | VisitedLinkSlave::VisitedLinkSlave() : shared_memory_(NULL) {} 18 | 19 | VisitedLinkSlave::~VisitedLinkSlave() { 20 | FreeTable(); 21 | } 22 | 23 | bool VisitedLinkSlave::OnControlMessageReceived(const IPC::Message& message) { 24 | bool handled = true; 25 | IPC_BEGIN_MESSAGE_MAP(VisitedLinkSlave, message) 26 | IPC_MESSAGE_HANDLER(ChromeViewMsg_VisitedLink_NewTable, 27 | OnUpdateVisitedLinks) 28 | IPC_MESSAGE_HANDLER(ChromeViewMsg_VisitedLink_Add, OnAddVisitedLinks) 29 | IPC_MESSAGE_HANDLER(ChromeViewMsg_VisitedLink_Reset, OnResetVisitedLinks) 30 | IPC_MESSAGE_UNHANDLED(handled = false) 31 | IPC_END_MESSAGE_MAP() 32 | return handled; 33 | } 34 | 35 | // This function's job is to initialize the table with the given 36 | // shared memory handle. This memory is mapped into the process. 37 | void VisitedLinkSlave::OnUpdateVisitedLinks(base::SharedMemoryHandle table) { 38 | DCHECK(base::SharedMemory::IsHandleValid(table)) << "Bad table handle"; 39 | // since this function may be called again to change the table, we may need 40 | // to free old objects 41 | FreeTable(); 42 | DCHECK(shared_memory_ == NULL && hash_table_ == NULL); 43 | 44 | // create the shared memory object 45 | shared_memory_ = new base::SharedMemory(table, true); 46 | if (!shared_memory_) 47 | return; 48 | 49 | // map the header into our process so we can see how long the rest is, 50 | // and set the salt 51 | if (!shared_memory_->Map(sizeof(SharedHeader))) 52 | return; 53 | SharedHeader* header = 54 | static_cast(shared_memory_->memory()); 55 | DCHECK(header); 56 | int32 table_len = header->length; 57 | memcpy(salt_, header->salt, sizeof(salt_)); 58 | shared_memory_->Unmap(); 59 | 60 | // now do the whole table because we know the length 61 | if (!shared_memory_->Map(sizeof(SharedHeader) + 62 | table_len * sizeof(Fingerprint))) { 63 | shared_memory_->Close(); 64 | return; 65 | } 66 | 67 | // commit the data 68 | DCHECK(shared_memory_->memory()); 69 | hash_table_ = reinterpret_cast( 70 | static_cast(shared_memory_->memory()) + sizeof(SharedHeader)); 71 | table_length_ = table_len; 72 | } 73 | 74 | void VisitedLinkSlave::OnAddVisitedLinks( 75 | const VisitedLinkSlave::Fingerprints& fingerprints) { 76 | for (size_t i = 0; i < fingerprints.size(); ++i) 77 | WebView::updateVisitedLinkState(fingerprints[i]); 78 | } 79 | 80 | void VisitedLinkSlave::OnResetVisitedLinks() { 81 | WebView::resetVisitedLinkState(); 82 | } 83 | 84 | void VisitedLinkSlave::FreeTable() { 85 | if (shared_memory_) { 86 | delete shared_memory_; 87 | shared_memory_ = NULL; 88 | } 89 | hash_table_ = NULL; 90 | table_length_ = 0; 91 | } 92 | 93 | } // namespace visitedlink 94 | -------------------------------------------------------------------------------- /src/renderer/visitedlink/visitedlink_slave.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef COMPONENTS_VISITEDLINK_RENDERER_VISITEDLINK_SLAVE_H_ 6 | #define COMPONENTS_VISITEDLINK_RENDERER_VISITEDLINK_SLAVE_H_ 7 | 8 | #include "base/compiler_specific.h" 9 | #include "base/memory/shared_memory.h" 10 | #include "src/common/visitedlink/visitedlink_common.h" 11 | #include "content/public/renderer/render_process_observer.h" 12 | 13 | namespace visitedlink { 14 | 15 | // Reads the link coloring database provided by the master. There can be any 16 | // number of slaves reading the same database. 17 | class VisitedLinkSlave : public VisitedLinkCommon, 18 | public content::RenderProcessObserver { 19 | public: 20 | VisitedLinkSlave(); 21 | virtual ~VisitedLinkSlave(); 22 | 23 | // RenderProcessObserver implementation. 24 | virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; 25 | 26 | // Message handlers. 27 | void OnUpdateVisitedLinks(base::SharedMemoryHandle table); 28 | void OnAddVisitedLinks(const VisitedLinkSlave::Fingerprints& fingerprints); 29 | void OnResetVisitedLinks(); 30 | 31 | private: 32 | void FreeTable(); 33 | 34 | // shared memory consists of a SharedHeader followed by the table 35 | base::SharedMemory* shared_memory_; 36 | 37 | DISALLOW_COPY_AND_ASSIGN(VisitedLinkSlave); 38 | }; 39 | 40 | } // namespace visitedlink 41 | 42 | #endif // COMPONENTS_VISITEDLINK_RENDERER_VISITEDLINK_SLAVE_H_ 43 | -------------------------------------------------------------------------------- /tools/copy_binary.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import shutil 5 | import stat 6 | import sys 7 | 8 | src = sys.argv[1] 9 | dist = sys.argv[2] 10 | 11 | shutil.copyfile(src, dist) 12 | os.chmod(dist, os.stat(dist).st_mode | stat.S_IEXEC) 13 | -------------------------------------------------------------------------------- /tools/mac/apply_locales.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Copyright (c) 2009 The Chromium Authors. All rights reserved. 3 | # Use of this source code is governed by a BSD-style license that can be 4 | # found in the LICENSE file. 5 | 6 | # TODO: remove this script when GYP has for loops 7 | 8 | import sys 9 | import optparse 10 | 11 | def main(argv): 12 | 13 | parser = optparse.OptionParser() 14 | usage = 'usage: %s [options ...] format_string locale_list' 15 | parser.set_usage(usage.replace('%s', '%prog')) 16 | parser.add_option('-d', dest='dash_to_underscore', action="store_true", 17 | default=False, 18 | help='map "en-US" to "en" and "-" to "_" in locales') 19 | 20 | (options, arglist) = parser.parse_args(argv) 21 | 22 | if len(arglist) < 3: 23 | print 'ERROR: need string and list of locales' 24 | return 1 25 | 26 | str_template = arglist[1] 27 | locales = arglist[2:] 28 | 29 | results = [] 30 | for locale in locales: 31 | # For Cocoa to find the locale at runtime, it needs to use '_' instead 32 | # of '-' (http://crbug.com/20441). Also, 'en-US' should be represented 33 | # simply as 'en' (http://crbug.com/19165, http://crbug.com/25578). 34 | if options.dash_to_underscore: 35 | if locale == 'en-US': 36 | locale = 'en' 37 | locale = locale.replace('-', '_') 38 | results.append(str_template.replace('ZZLOCALE', locale)) 39 | 40 | # Quote each element so filename spaces don't mess up GYP's attempt to parse 41 | # it into a list. 42 | print ' '.join(["'%s'" % x for x in results]) 43 | 44 | if __name__ == '__main__': 45 | sys.exit(main(sys.argv)) -------------------------------------------------------------------------------- /tools/mac/create-framework-subdir-symlinks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | cd "${BUILT_PRODUCTS_DIR}/${1}.framework" 6 | shift 7 | 8 | while [ ! -z "${1}" ]; do 9 | ln -sf Versions/Current/"${1}" "${1}" 10 | shift 11 | done 12 | -------------------------------------------------------------------------------- /tools/mac/make_locale_dirs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2011 The Chromium Authors. All rights reserved. 4 | # Use of this source code is governed by a BSD-style license that can be 5 | # found in the LICENSE file. 6 | 7 | # usage: make_locale_dirs.sh locale_dir [...] 8 | # 9 | # This script creates the Resources directory for the bundle being built by 10 | # the Xcode target that calls it if the directory does not yet exist. It then 11 | # changes to that directory and creates subdirectories for each locale_dir 12 | # passed on the command line. 13 | # 14 | # This script is intended to create empty locale directories (.lproj) in a 15 | # Cocoa .app bundle. The presence of these empty directories is sufficient to 16 | # convince Cocoa that the application supports the named localization, even if 17 | # an InfoPlist.strings file is not provided. Chrome uses these empty locale 18 | # directoires for its helper executable bundles, which do not otherwise 19 | # require any direct Cocoa locale support. 20 | 21 | set -eu 22 | 23 | if [[ ${#} -eq 0 ]]; then 24 | echo "usage: ${0} locale_dir [...]" >& 2 25 | exit 1 26 | fi 27 | 28 | RESOURCES_DIR="${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 29 | if [[ ! -d "${RESOURCES_DIR}" ]]; then 30 | mkdir "${RESOURCES_DIR}" 31 | fi 32 | 33 | cd "${RESOURCES_DIR}" 34 | 35 | for dir in "${@}"; do 36 | if [[ ! -d "${dir}" ]]; then 37 | mkdir "${dir}" 38 | fi 39 | done 40 | -------------------------------------------------------------------------------- /tools/posix/make_locale_paks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2011 The Chromium Authors. All rights reserved. 4 | # Use of this source code is governed by a BSD-style license that can be 5 | # found in the LICENSE file. 6 | 7 | # usage: make_locale_paks locale_dir [...] 8 | # 9 | # This script creates the .pak files under locales directory, it is used to fool 10 | # the ResourcesBundle that the locale is available. 11 | 12 | set -eu 13 | 14 | if [[ ${#} -eq 0 ]]; then 15 | echo "usage: ${0} build_dir [locale_pak...]" >& 2 16 | exit 1 17 | fi 18 | 19 | PRODUCT_DIR="$1" 20 | shift 21 | 22 | LOCALES_DIR="${PRODUCT_DIR}/locales" 23 | if [[ ! -d "${LOCALES_DIR}" ]]; then 24 | mkdir "${LOCALES_DIR}" 25 | fi 26 | 27 | cd "${LOCALES_DIR}" 28 | 29 | for pak in "${@}"; do 30 | if [[ ! -f "${pak}.pak" ]]; then 31 | touch "${pak}.pak" 32 | fi 33 | done 34 | -------------------------------------------------------------------------------- /tools/posix/strip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Ignore errors from strip. 4 | strip "$@" 5 | 6 | exit 0 7 | -------------------------------------------------------------------------------- /tools/source_root.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | 5 | """Prints the absolute path of the root of atom-shell's source tree. 6 | """ 7 | 8 | 9 | print os.path.abspath(os.path.dirname(os.path.dirname(__file__))) 10 | --------------------------------------------------------------------------------