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

Side by Side Diff: mojo/runner/android/android_handler.cc

Issue 1189703004: Reland: Build Mojo apps in sub-dirs, like application packages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup, move getAssetsList to FileHelper; rename local to cached. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/runner/android/android_handler.h" 5 #include "mojo/runner/android/android_handler.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 base::UnloadNativeLibrary(app_library); 73 base::UnloadNativeLibrary(app_library);
74 } 74 }
75 75
76 // Returns true if |url| denotes a cached app. If true |app_dir| is set to the 76 // Returns true if |url| denotes a cached app. If true |app_dir| is set to the
77 // path of the directory for the app and |path_to_mojo| the path of the app's 77 // path of the directory for the app and |path_to_mojo| the path of the app's
78 // .mojo file. 78 // .mojo file.
79 bool IsCachedApp(JNIEnv* env, 79 bool IsCachedApp(JNIEnv* env,
80 const GURL& url, 80 const GURL& url,
81 base::FilePath* app_dir, 81 base::FilePath* app_dir,
82 base::FilePath* path_to_mojo) { 82 base::FilePath* path_to_mojo) {
83 ScopedJavaLocalRef<jstring> j_local_apps_dir = 83 ScopedJavaLocalRef<jstring> j_cached_apps_dir =
84 Java_AndroidHandler_getLocalAppsDir(env, GetApplicationContext()); 84 Java_AndroidHandler_getCachedAppsDir(env, GetApplicationContext());
85 const base::FilePath local_apps_fp( 85 const base::FilePath cached_apps_fp(
86 ConvertJavaStringToUTF8(env, j_local_apps_dir.obj())); 86 ConvertJavaStringToUTF8(env, j_cached_apps_dir.obj()));
87 const std::string local_apps(util::FilePathToFileURL(local_apps_fp).spec()); 87 const std::string cached_apps(util::FilePathToFileURL(cached_apps_fp).spec());
88 const std::string response_url(GURL(url).spec()); 88 const std::string response_url(GURL(url).spec());
89 if (response_url.size() <= local_apps.size() || 89 if (response_url.size() <= cached_apps.size() ||
90 local_apps.compare(0u, local_apps.size(), response_url, 0u, 90 cached_apps.compare(0u, cached_apps.size(), response_url, 0u,
91 local_apps.size()) != 0) { 91 cached_apps.size()) != 0) {
92 return false; 92 return false;
93 } 93 }
94 94
95 const std::string mojo_suffix(".mojo"); 95 const std::string mojo_suffix(".mojo");
96 // app_rel_path is either something like html_viewer/html_viewer.mojo, or 96 // app_rel_path is either something like html_viewer/html_viewer.mojo, or
97 // html_viewer.mojo, depending upon whether the app has a package. 97 // html_viewer.mojo, depending upon whether the app has a package.
98 const std::string app_rel_path(response_url.substr(local_apps.size() + 1)); 98 const std::string app_rel_path(response_url.substr(cached_apps.size() + 1));
99 const size_t slash_index = app_rel_path.find('/'); 99 const size_t slash_index = app_rel_path.find('/');
100 if (slash_index != std::string::npos) { 100 if (slash_index != std::string::npos) {
101 const std::string tail = 101 const std::string tail =
102 app_rel_path.substr(slash_index + 1, std::string::npos); 102 app_rel_path.substr(slash_index + 1, std::string::npos);
103 const std::string head = app_rel_path.substr(0, slash_index); 103 const std::string head = app_rel_path.substr(0, slash_index);
104 if (head.find('/') != std::string::npos || 104 if (head.find('/') != std::string::npos ||
105 tail.size() <= mojo_suffix.size() || 105 tail.size() <= mojo_suffix.size() ||
106 tail.compare(tail.size() - mojo_suffix.size(), tail.size(), 106 tail.compare(tail.size() - mojo_suffix.size(), tail.size(),
107 mojo_suffix) != 0) { 107 mojo_suffix) != 0) {
108 return false; 108 return false;
109 } 109 }
110 *app_dir = local_apps_fp.Append(head); 110 *app_dir = cached_apps_fp.Append(head);
111 *path_to_mojo = app_dir->Append(tail); 111 *path_to_mojo = app_dir->Append(tail);
112 return true; 112 return true;
113 } 113 }
114 if (app_rel_path.find('/') != std::string::npos || 114 if (app_rel_path.find('/') != std::string::npos ||
115 app_rel_path.size() <= mojo_suffix.size() || 115 app_rel_path.size() <= mojo_suffix.size() ||
116 app_rel_path.compare(app_rel_path.size() - mojo_suffix.size(), 116 app_rel_path.compare(app_rel_path.size() - mojo_suffix.size(),
117 mojo_suffix.size(), mojo_suffix) != 0) { 117 mojo_suffix.size(), mojo_suffix) != 0) {
118 return false; 118 return false;
119 } 119 }
120 120
121 *app_dir = local_apps_fp.Append( 121 *app_dir = cached_apps_fp.Append(
122 app_rel_path.substr(0, app_rel_path.size() - mojo_suffix.size())); 122 app_rel_path.substr(0, app_rel_path.size() - mojo_suffix.size()));
123 *path_to_mojo = local_apps_fp.Append(app_rel_path); 123 *path_to_mojo = cached_apps_fp.Append(app_rel_path);
124 return true; 124 return true;
125 } 125 }
126 126
127 } // namespace 127 } // namespace
128 128
129 AndroidHandler::AndroidHandler() : content_handler_factory_(this) { 129 AndroidHandler::AndroidHandler() : content_handler_factory_(this) {
130 } 130 }
131 131
132 AndroidHandler::~AndroidHandler() { 132 AndroidHandler::~AndroidHandler() {
133 } 133 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 connection->AddService(&content_handler_factory_); 174 connection->AddService(&content_handler_factory_);
175 return true; 175 return true;
176 } 176 }
177 177
178 bool RegisterAndroidHandlerJni(JNIEnv* env) { 178 bool RegisterAndroidHandlerJni(JNIEnv* env) {
179 return RegisterNativesImpl(env); 179 return RegisterNativesImpl(env);
180 } 180 }
181 181
182 } // namespace runner 182 } // namespace runner
183 } // namespace mojo 183 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/runner/BUILD.gn ('k') | mojo/runner/android/apk/src/org/chromium/mojo/shell/AndroidHandler.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698